Home » Difference between Shared Memory and Message Passing in Operating System

Difference between Shared Memory and Message Passing in Operating System

by Online Tutorials Library

Difference between Shared Memory and Message Passing in Operating System

In this article, you will learn the difference between shared memory and memory passing. But before discussing the differences, you must know about the shared memory and message passing.

What is Shared Memory?

The fundamental model of inter-process communication is the shared memory system. In a shared memory system, the collaborating communicates with each other by establishing the shared memory region in the address space region.

If the process wishes to initiate communication and has data to share, create a shared memory region in its address space. After that, if another process wishes to communicate and tries to read the shared data, it must attach to the starting process’s shared address space.

What is Message Passing?

In this message passing process model, the processes communicate with others by exchanging messages. A communication link between the processes is required for this purpose, and it must provide at least two operations: transmit (message) and receive (message). Message sizes might be flexible or fixed.

Key differences between the Shared Memory and Message Passing

Difference between Shared Memory and Message Passing in Operating System

Here, you will learn the various key differences between Shared Memory and Message Passing. Various differences between Shared Memory and Message Passing are as follows:

  1. Shared memory is used to communicate between the single processor and multiprocessor systems. The communication processes are on the same machine and share the same address space. On the other hand, message passing is most commonly utilized in a distributed setting when communicating processes are spread over multiple devices linked by a network.
  2. Shared memory offers a maximum computation speed because communication is completed via the shared memory, so the system calls are only required to establish the shared memory. On the other hand, message passing takes time because it is performed via the kernel (system calls).
  3. The shared memory region is mainly used for data communication. On the other hand, message passing is mainly used for communication.
  4. Make sure that processes in shared memory aren’t writing to the same address simultaneously. On the other hand, message passing is useful for sharing little quantities of data without causing disputes.
  5. The code for reading and writing the data from the shared memory should be written explicitly by the developer. On the other hand, no such code is required in this case because the message passing feature offers a method for communication and synchronization of activities executed by the communicating processes.

Head-to-head comparison between Shared Memory the Message Passing

Here, you will learn the head-to-head comparisons between the Shared Memory and the Message Passing. The main differences between the Shared Memory and the Message Passing are as follows:

Shared Memory Message Passing
It is mainly used for data communication. It is mainly used for communication.
It offers a maximum speed of computation because communication is completed via the shared memory, so the system calls are only required to establish the shared memory. It takes a huge time because it is performed via the kernel (system calls).
The code for reading and writing the data from the shared memory should be written explicitly by the developer. No such code is required in this case because the message passing feature offers a method for communication and synchronization of activities executed by the communicating processes.
It is used to communicate between the single processor and multiprocessor systems in which the processes to be communicated are on the same machine and share the same address space. It is most commonly utilized in a distributed setting when communicating processes are spread over multiple devices linked by a network.
It is a faster communication strategy than the message passing. It is a relatively slower communication strategy than the shared memory.
Make sure that processes in shared memory aren’t writing to the same address simultaneously. It is useful for sharing little quantities of data without causing disputes.

You may also like