Open In App

Difference between Shared Memory Model and Message Passing Model in IPC

Last Updated : 16 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Inter-Process Communication (IPC) is a critical aspect of modern operating systems, enabling processes to exchange data and synchronize their actions. Two primary models for IPC are the Shared Memory Model and the Message Passing Model. In the modern operating system, the Inter-Process Communication (IPC) is a very important element. It enables some processes that help to exchange data and synchronize their actions.

What is the Shared Memory Model?

In this IPC Model, a shared memory region is established which is used by the processes for data communication. This memory region is present in the address space of the process which creates the shared memory segment. The processes that want to communicate with this process should attach this memory segment to their address space. 

Advantages of the Shared Memory Model

  • Fast Communication: As seen, all the processes can directly access the memory and therefore, the rates of communication are fast.
  • Efficient for Large Data Transfers: The data structures can be passed from one process to another in large blocks at once, however, there is no need to copy it in every process memory space.
  • Less Kernel Involvement: This was said because after the shared memory space has been established, the kernel doesn’t have to keep on transferring data from one process to another, which in the long run, is costly.

Disadvantages of the Shared Memory Model

  • Complex Synchronization: A process has to take care of such synchronization tools and gadgets as semaphores or mutexes to prevent racing conditions.
  • Security Risks: Sharing memory is disadvantageous because processes that are running in this location are vulnerable to security threats as everyone who ard the data can access it.
  • Limited to a Single Machine: In a distributed system it can only be used for processes inside the same machine.

What is the Message Passing Model? 

In this model, the processes communicate with each other by exchanging messages. For this purpose, a Communication Link must exist between the processes and it must facilitate at least two operations send (message) and receive (message). The size of messages may be variable or fixed. 

Advantages of the Message Passing Model

  • Simplicity: Memory management is hidden on the message-passing model, which sort of makes the actual process communication more straightforward.
  • No Synchronization Required: In case of processes, there’s no requirement to communicate memory as they do not have access to it hence no issues on synchronization.
  • Distributed Systems Friendly: Due to such support of communication between processes on two different machines, this model is adopted in distributed systems.

Disadvantages of the Message Passing Model

  • Slower Communication: The use of message passing entails data copies in the course of data transfer between processes, which widen the communication impendence especially with voluminous data sets.
  • More Kernel Involvement: Since interaction occurs in the kernel, there is high overhead since each sent or received message needs interaction.
  • Higher Resource Consumption: A transmission of messages may be more costly compared to direct access to memory particularly so when data volume is large.

Difference Between The Shared Memory Model and Message Passing Model in IPC

Shared Memory ModelMessage Passing Model
The shared memory region is used for communication.A message-passing facility is used for communication.
It is used for communication between processes on a single processor or multiprocessor system where the communicating processes reside on the same machine as the communicating processes share a common address space.It is typically used in a distributed environment where communicating processes reside on remote machines connected through a network.
The code for reading and writing the data from the shared memory should be written explicitly by the Application programmer.No such code is required here as the message-passing facility provides a mechanism for communication and synchronization of actions performed by the communicating processes.
It provides a maximum speed of computation as communication is done through shared memory so system calls are made only to establish the shared memory.It is time-consuming as message passing is implemented through kernel intervention (system calls).
Here the processes need to ensure that they are not writing to the same location simultaneously.It is useful for sharing small amounts of data as conflicts need not be resolved.
Faster communication strategy.Relatively slower communication strategy.
No kernel intervention.It involves kernel intervention.
It can be used in exchanging larger amounts of data. It can be used in exchanging small amounts of data.

Example- 

  • Data from a client process may need to be transferred to a server process for modification before being returned to the client.

Example- 

  • Web browsers
  • Web Servers
  • Chat program on WWW (World Wide Web)

Conclusion

In Conclusion, both the Shared Memory Model and Message Passing Model serve the same fundamental purpose of facilitating communication between processes, they differ significantly. The above difference table between the IPC Shared Memory Model and Message Passing Model will help to clear all the doubts related to communication in IPC.


Next Article

Similar Reads