An operating system provides inter-process communication to allow processes to exchange information. Inter-process communication allows programmers to coordinate activities among various processes that are concurrently running in the system.
Processes in the system are of two types:
Independent processes are those processes which neither affect nor get affected by other processes running in the system. In other words, Any process that does not share data with other processes is an independent process.
Cooperating processes are those if they can affect or get affected by the other processes running in the system. In other words, a process that shares data with other processes is a cooperating process.
Inter-process communication is useful for creating cooperating processes. For example, ‘ls‘ process and ‘more‘ process can cooperate to produce a paged listing of files and directories.
The cooperating processes are important because they provide:
Broadly there are two approaches of implementing inter-process communication
Cooperating processes share a region of memory. It is the fastest method for inter-process communication. The operating system creates a common memory segment in the RAM so that several processes can read and write in that memory segment. The processes share the memory region without calling operating system functions.
Advantages of Shared Memory
Disadvantages of Shared Memory
It is the second method for inter process communication. It provides two operations for processes to communicate.
Message passing is slower as compared to shared memory method. This is because it makes use of system calls to provide communication between processes.
To send and receive messages in message passing, a communication link is required between two processes. There are various ways to implement a communication link.
In direct communication, each process must explicitly name the recipient or sender of the communication.
send(P, message) – send a message to process P receive(Q, message) – receive a message from process Q
In this method, the link is automatically established. The process must only know the identity of the other process. Link is always created between two processes. One direct link can be used only between one pair of communicating processes. For example, if there two links L1 and L2 then only two processes P1 and P2 can use L1. P3 and P4 can not use L1. Also, two processes can use only a single direct link for communication. For example, P1 and P2 can use only L1 but can not use L2 for communication.
In indirect communication, messages are sent and received through mailboxes or ports.
send(A, message) – send a message to mailbox A
receive (A, message) – receive a message from mailbox A
Different pair of processes can use the same indirect link for communication. For example, if there is a link L1. Then a pair of processes P1 and P2 and also P3 and P4 can use L1 for communication. Also, two processes can two different indirect links for communication. For example, processes P1 and P2 can use only link L1 as well as link L2 for communication.
Message passing may be blocking (synchronous) or non blocking (non-synchronous)
The speed of the sender and receiver process can be different. So, it is important to introduce some kind of temporary storage. For example, if your internet connection is slow, the video in youtube gets buffered. The messages exchanged by the communicating process reside in a temporary queue. There are three ways to implement queues.
Shared Memory | Message Passing |
Processes exchange information by reading or writing into the shared region | There is direct exchange of messages between processes |
It is Useful for exchange of large amount of data | Useful when exchanging small amount of data |
It is Faster than message passing as system calls are required only to establish shared region | It is Slower than shared memory because it is implemented using system calls |
The above discussion is summarized in the form of a PPT with animations below.
Note: Click within the slide area for animations. Clicking on the “next” slide button will not display any animation
Previous Next
Disk Scheduling Security