Differentiate between shared memory and message passing model in OS.

Operating SystemHardwareSoftware & Coding

Shared memory system is the fundamental model of inter process communication. In a shared memory system, in the address space region the cooperating communicate with each other by establishing the shared memory region.

Shared memory concept works on fastest inter process communication.

If the process wants to initiate the communication and it has some data to share, then establish the shared memory region in its address space.

After that, another process wants to communicate and tries to read the shared data, and must attach itself to the initiating process’s shared address space.

Message Passing provides a mechanism to allow processes to communicate and to synchronize their actions without sharing the same address space.

For example − Chat program on the World Wide Web.

Message passing provides two operations which are as follows −

  • Send message

  • Receive message

Messages sent by a process can be either fixed or variable size.

For fixed size messages the system level implementation is straight forward. It makes the task of programming more difficult.

The variable sized messages require a more system level implementation but the programming task becomes simpler.

If process P1 and P2 want to communicate they need to send a message to and receive a message from each other that means here a communication link exists between them.

Differences

The major differences between shared memory and message passing model −

Shared MemoryMessage Passing
It is one of the region for data communicationMainly the message passing is used for communication.
It is used for communication between single processor and multiprocessor systems where the processes that are to be communicated present on the same machine and they are sharing common address space.It is used in distributed environments where the communicating processes are present on remote machines which are connected with the help of a network.
The shared memory code that has to be read or write the data that should be written explicitly by the application programmer.Here no code is required because the message passing facility provides a mechanism for communication and synchronization of actions that are performed by the communicating processes.
It is going to provide a maximum speed of computations because the communication is done with the help of shared memory so system calls are used to establish the shared memory.Message passing is a time consuming process because it is implemented through kernel (system calls).
In shared memory make sure that the processes are not writing to the same location simultaneously.Message passing is useful for sharing small amounts of data so that conflicts need not occur.
It follows a faster communication strategy when compared to message passing technique.In message passing the communication is slower when compared to shared memory technique.
Given below is the structure of shared memory system −
Given below is the structure of message passing system −
raja
Updated on 30-Nov-2021 10:38:48

Advertisements