Inter-process Communication in OS. Explain its two models

Inter-process communication is a mechanism that allows processes to communicate with each other. The processes of two different computers that connect with the same network can also communicate via Inter-process communication. Communication between the processes should take place in a well-structured manner.

It is used to exchange essential information between threads in single or multiple processes. The main goal of inter-process communication is to facilitate communication between different processes.

Inter-process communication is known as Dynamic data exchange system in windows. In a multiprogramming operating system, multiple processes may be executed simultaneously.

In the context of inter-process communication,

We can classify processes into two categories

  • Independent Process: Independent processes never share their data with other processes, and these processes never ask other processes for data sharing. This process functions independently in the multiprogramming operating system. 
  • Cooperative Process: These processes are just alternatives to independent processes. They share their data with other processes in the system. 

There are two types of models in inter-process communication

1). Shared memory model

The shared memory model creates a region of memory that gets shared between two or more cooperating processes. This model is faster than the message-passing model. Generally, OS prevents the processes from entering the memory of different processes, but we bypass this prevention in this situation. The process itself permits the operating system to eliminate this protection from its memory for the cooperative process. 

Advantages:

  • Faster data access and transfer, as it eliminates the need for system calls involved in message passing.
  • More efficient for sharing large amounts of data between processes.

Disadvantages:

  • Requires careful synchronization to avoid concurrency issues like race conditions.
  • Processes must establish a way to manage the layout and usage of the shared memory region.

Use Cases: Ideal for high-performance computing applications where processes on the same machine need to exchange large data sets rapidly, such as in scientific simulations or real-time data processing systems.

2). Message Passing model

In the message-passing model, two processes communicate with each other by passing messages. The message-passing model is more useful in the distributed environment when the two devices are connected with the same network, and their process wants to share data. It is quite easy to implement as compared to the shared memory model. It is used to interchange a small amount of data. The message-passing model provides two operations: send a message and receive a message. 

Advantages:

  • Simplifies the design of communicating processes, especially in distributed systems.
  • No need for shared state or data structures, reducing the complexity of concurrency problems.

Disadvantages:

  • Overhead of message encoding and decoding.
  • Potentially higher latency compared to shared memory, especially for large data transfers.

Use Cases: Suitable for distributed systems where processes run on different machines, such as client-server applications and microservices architectures.