Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Shared memory system 

is the fundamental model of inter process communication.


In a shared memory system, the cooperating processes communicate with each
other by establishing a shared memory region in the address space. 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 it establishes the shared memory region in its address space.
 After that, if another process wants to communicate and tries to read the
shared data, it 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. If process P1 and
P2 want to communicate, send a message and receive a message from each other,
a communication link must exist between them. For example: Chat program on the
World Wide Web (WWW).
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.
Messages are stored on the queue until their recipient retrieves them. Message
queues are quite useful for inter-process communication and are used by most
operating systems. A diagram that demonstrates message passing model of process
communication is given as follows −

In the above diagram, both the processes P1 and P2 can access the message
queue and store and retrieve data.
Kernel will pick one message from queue, one at a time and examine it and passes it to the
destination process. All steps dependent on kernel.

When process B is ready then only it can receive hence it is not synchronous, it asynchronous
communication.
Each queue has ID

Why do we need message queues when we already have the shared memory?
It would be for multiple reasons, let us try to break this into multiple points for
simplification:
 As understood, once the message is received by a process it would be no
longer available for any other process. Whereas in shared memory, the data
is available for multiple processes to access.
 If we want to communicate with small message formats.
 Shared memory data need to be protected with synchronization when
multiple processes communicating at the same time.
 Frequency of writing and reading using the shared memory is high, then it
would be very complex to implement the functionality. Not worth with regard
to utilization in this kind of cases.
 What if all the processes do not need to access the shared memory but very
few processes only need it, it would be better to implement with message
queues.
 If we want to communicate with different data packets, say process A is
sending message type 1 to process B, message type 10 to process C, and
message type 20 to process D. In this case, it is simplier to implement with
message queues.
 Ofcourse, the order of message queue is FIFO (First In First Out). The first
message inserted in the queue is the first one to be retrieved.
 Using Shared Memory or Message Queues depends on the need of the
application and how effectively it can be utilized.
Mail box server and mail box client

You might also like