Interprocess Communication

What is Interprocess Communication?

Interprocess communication is communication between two concurrently executing processes. But, the concurrently executing processes in the system can be of two types – independent processes and cooperating processes.

An Independent process is one that 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. These reasons include sharing the same piece of information, increasing computation speed, and executing multiple tasks at a time. Interprocess communication is a mechanism of sharing data and information among the cooperating processes.

Table of Contents

  1. Two Methods of Interprocess Communication

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.

Interprocess Communication shared memory system

But we all know that the operating system restricts any process from accessing other processes’ 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 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 ensure 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.

An accurate example of processes performing interprocess communication would be a compiler. A compiler generates the assembly code that would be used by the assembler, which in turn generates an object module that would be used by the loader.

The processes of sharing information must work concurrently, like a producer will keep on producing, and the consumer will keep on consuming. They have to ensure that the consumer must never consume a process that is yet to be produced.

Must Read: Process Scheduling

The solution to this would be a buffer. The buffer will reside in the memory of the process, creating a shared memory segment. There must be proper synchronization of both the producer process and consumer process 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 an 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 information between the cooperating processes does not require the interference of the operating system. It’s the responsibility of the application programmer to provide the means of sharing and accessing the shared information.

Must Read: Difference Between Shared Memory and Message Passing System

Message Passing System

Opposite to the shared memory systems, 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.

Interprocess Communication message passing system

The message-passing system can be used when the communicating processes are running two different systems connected with the network. An example of this could be a chat going on between two systems connected with the world wide 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. The system implementation is difficult for the variable size message, but the programming is easy.

The message passing could be direct or indirect. The former communication, i.e. direct communication, in which the communicating processes must specifically identify each other, and a direct link is established between the communicating process. Later communication, i.e. 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 when the sending process stops sending another message until the first message sent is received by the receiver. Asynchronous message passing is when the sending process sends the message but does not wait for the receiver to receive the message. Further, it resumes its work after sending the message.

So, these are the means which can be used to establish interprocess communication.

Leave a Reply

Your email address will not be published. Required fields are marked *