Sie sind auf Seite 1von 8

Co Operating Process: Those Processes that communicate with each other are known as co operating processes.

They communicate through different mechanisms. For Information Sharing, Computation Speedup, Modularity & Convenience. Problem in Communication:

Example, in which one process is producing data and another process is consuming the data. The data is passed via an intermediary buffer, which may be either unbounded or bounded. With a bounded buffer the producer may have to wait until there is space available in the buffer, but with an unbounded buffer the producer will never need to wait. The consumer may need to wait in either case until there is data available. This example uses shared memory and a circular queue. Note that only the producer changes "in", and only the consumer changes "out", and that they can never be accessing the same array location at the same time.

How inter process Communicate? Messaging ( Send, Receive) ( Fixed Length, Variable Length) (Direct, Indirect) Direct & Indirect Half & Full Duplex Direct VS Indirect Direct: One to One, Single Sender & Receiver (Channel). Indirect: One to One but receipt in unknown, Multiple Senders & Receivers.

Inter Process Communication (IPC) A capability supported by some operating systems that allows one process to communicate with another process. The processes can be running on the same computer or on different computers connected through a network. Its Synchronization Sending or Receiving of Message Wait or Unwait Blocked or Unblocked Synchronous or Asynchronous

Its Buffering (Queue is made) Zero Capacity: One data packet is send. Message is not stored in the queue, so sender blocks until receiver accept the messages. Bounded Capacity: More than one packet but not unlimited. Unbounded Capacity: Unlimited & Infinite

Tools of IPC PIPE Pipes were evolved in the most primitive forms of the Unix operating system. They provide unidirectional flow of communication between processes within the same system. In other words, they are half-duplex that is, data flows in only one direction. Command cmd1 | cmd2 PIPE Calls PIPE (Create) , Read, Write , Close (Destroy) Id (Represent), Data in the form of Streaming, Bounded Buffer. Per Process File Descriptor Table (PPFDT) A per-process file descriptor table, stored in each process's process table entry A file descriptor used in read, write and other system calls is an index into this table. Each entry contains a pointer to the kernel file table. PIPE Create Return Type (ID) If -1, Then Too many Pipes, PPFDT out of Space 2 Files (Read & Write) (Diagram)=> Parent creates a child and a pipe. Child uses the pipe to send data to parent. Parent displays the data. PIPE Named PIPE (FIFO) Socket Transport Layer Interface (TLI) Message Queues Shared Memory

Code For PIPE


/* Parent creates pipe, forks a child, child writes into pipe, and parent reads from pipe */ main() { int pipefd[2], pid, n, rc, nr, status; //fd for read & write char *testString = "Hello, world!\n", buf[1024]; rc = pipe (pipefd); if (rc < 0) { perror("pipe"); } pid = fork (); if (pid < 0) { perror("fork"); } if (pid == 0) { /* Childs Code */

close(pipefd[0]); write(pipefd[1], testString, strlen(testString)); close(pipefd[1]);

} /* Parents Code */ else close(pipefd[1]); n = strlen(testString); nr = read(pipefd[0], buf, n); rc = write(1, buf, nr); wait(&status); printf("Good work child!\n"); return(0); }

RE: Types of IPC

PIPE: Related Process (Child/parent, G.child/G.parent,Sibling) With in a System (Diagram)

FIFO: Unrelated & Related Process (With in a system) (Diagram)

Socket: Related & Unrelated Process. Within a system, at network level & outside a system. (Diagram)

System Calls For IPC Open: int open (Const char *path, int 0 flag, /*mode*/); Read: ssize-t read (int fdese, void *buf, size t nbyte); Write: ssize-t write (int fdese, void *buf, size t nbyte); Close: int close (int fdese); Pipe: int pipe (int fdese[2]);

Standard Descriptors: 3 file descriptors stores in start of PPFDT. Standard Input=location 0=Keyboard Standard Output=location 1=Display Standard Error=location 2=Display Changing Standard Descriptors Content Process is called redirection Cmd 0<input file Cmd 1>output file Cmd 2>error file Cat command is also used to display keyboard input instantly. FIFO Command: $Mknode fifo1 p //p is the name type

$ Mkfifo fifo1 $ prog 3 <0 fifo1 & //& for creating background process, <0 for read, write $ prog 1 <0 tempfile | tee fifo1 | prog2 // tee is used to write on fifo and display output as well

Linux Commands for Process Management Ps Listing of process e.g status, id, time etc Tap Listing of processes in sorted form depends on CPU usage Bg foreground running process shift to background Fg background running process shift to foreground Jobs Listing of jobs e.g status, id, time etc Ctrl + Z Suspend running process for sometime Ctrl + C Kill or Terminate a current process using interrupt Kill Terminate Selected Process

Threads It is inside the process. It is efficient than process. Can have multiple threads in single process. PPFDT is responsible for sharing threads in a process.

Threads Share PPFDT Current Working Directory Code/Data Interrupts (Global)

Threads Do not share Its own id Cpu Context (PC) Individual Scheduling Error number will be separate Priority

Thread VS Process Similarity: State and child creation Dis similarity: Same memory Space, No auto protection Mechanism

Advantages of Thread: Responsiveness Multiple thread parallel execution Resource Sharing Economical

Single VS Multiple Thread Single: Single Threaded Code Multiple: Multiple threaded code, parallel execution, 3 separate PCs Types of Threads (Existence Based) User Thread Kernel is involved in making thread but the kernel itself is unaware of user thread Kernel cannot send interrupts to user threads Process with user thread will not have fair scheduling Kernel Thread Kernel is aware of it Kernel can send interrupts Can do context switching etc Will be fair scheduling

Types of Model for Multiple Threading M to 1 11 MM Solaris 2T

Solaris 2T model: Introduces Light Weight Processes (LWP) For Each LWP, there must be kernel thread. Kernel threads may or may not be relate to LWP. Kernel is unaware of LWP

M- M model: Efficient Has M-1 or 1-1 model Concurrency May or may not be Blocking may or may not be Least possible overheads E.g Solaris 2, HP-UX

1-1 model: M-1 model:

Full concurrent because all are undivdual No blocking of threads due to system calls Drawback is this that kernel overhead for creation of kernel threads for each user thread E.g windows NT, 2000, OS-2

Multiple user threads connected to single kernel thread No concurrency On system call, all threads go to wait state E.g Posix P, Solaris 2 UI, Mach C

------------------------------------------------------------------------------------------------------------------------------------------

Das könnte Ihnen auch gefallen