Interprocess communication is communication between two concurrently executing processes. But, the concurrently executing processes in the system can be of two types of independent processes and cooperating processes. Independent process is one which neither affects nor gets affected by other processes in the system. The cooperating process is a process that affects other processes or can get affected by the other processes in the system.
The cooperating process shares data and information for several reasons like sharing the same piece of information, increasing computation speed, executing multiple tasks at a time. Interprocess communication is a mechanism of sharing data and information among the cooperating processes.
Two Methods of Interprocess Communication
Shared Memory System
In the shared memory interprocess communication model the processes involved in interprocess communication construct a shared memory region. This shared memory region is constructed in the address space of the process creating the shared memory.
And the other process that wants to access that shared information has to attach itself to the address space of the process that created the shared memory segment.
But, we all know that the operating system restricts any process from accessing other process’s memory. So, the cooperating processes must agree to overcome this restriction and share the memory of other processes.
Now, it’s up to the cooperating processes that which form of data and the memory location they will be using for sharing the information, the operating system has nothing to do with this.
It is the responsibility of cooperating processes to assure that they are not writing at the same memory location simultaneously. You can understand this better with the producer-consumer problem where a producer has to produce the information that will be consumed by the consumer.
The accurate example of processes performing interprocess communication would be a compiler generates the assembly code that would be used by the assembler which in turn generates object module that would be used by the loader.
The processes sharing information must work concurrently like a producer will keep on producing and the consumer will keep on consuming they have to ensure that consumer must never consume a process that is yet to be produced.
The solution to this would be a buffer that will be residing in the memory of the process creating a shared memory segment. Both the producer process as well as consumer process must be properly synchronized to prevent the consumer process from consuming the information that is yet to be generated.
Well, there can be constraints on the size of the buffer. Like buffer could be unbounded buffer where a consumer process may have to wait if the buffer is empty but the producer process may keep on producing.
The buffer could also be a bounded buffer where the producer process has to wait to produce new information if the buffer is full and the consumer has to wait if the buffer is empty.
This model of sharing the information between the cooperating processes does not require the interference of the operating system. It’s the responsibility of application programmer to provide the means of sharing and accessing the shared information.
Message Passing System
Opposite to shared memory system, the message passing system requires the operating system to provide the means of sharing and accessing the shared information between the cooperating processes.
The message passing system shares the data and information between the communicating process by sending and receiving of the message. The process that wants to share some information sends a message to the process that requires the shared information.
The message passing system can be used when the communicating processes are running two different systems connected with the network. The example for this could be, chat going on between two systems connected with the worldwide web.
Now a message could be a fixed size message or a variable size message. System implementation for the fixed-size message is easy but its programming is difficult as there is a constraint on the size of the message. For the variable size message, the system implementation is difficult but the programming is easy.
The message passing could be direct or indirect. The former communication i.e. the direct communication in which the communicating processes must specifically identify each other and a direct link is established between the communicating process. In later communication i.e. the indirect communication, is one where the message is sent and received via mailboxes or ports.
The message passing can be synchronous as well as asynchronous. Synchronous message passing is one where the sending process stops sending another message until the first message sent is received by the receiver. Asynchronous message passing is one where the sending process sends the message but do not wait for the receiver to receive the message and it resumes its work after sending the message.
So, these are the means which can be used to establish interprocess communication.