Message Passing System

In this article, you will learn another popular method of interprocess communication called message passing. You will learn different techniques and characteristics of message passing.


Message Passing

The cooperating processes can communicate with the help of a message passing facility. There are different ways communication happens:

  • Between same threads of a process.
  • Between processes on same node or computer.
  • Between two processes on different nodes or computers.
    Example: chat system over Internet

A message-passing system has atleast two primitive operations:

  1. send(message)
  2. receive(message)

The messages could be of a fixed size or a variable size. If system uses fixed size messages, then system level implementation is easy. If chosen variable size messages, the system level implementation is difficult, but the programming level task is easy.

If P and Q process wants to communicate, then a communication link must exist between them. There are several ways to implement physical link( shared memory, hardware, or network), but we are interested in logical implementation of a link. Here are different ways to communicate using message passing:

1. Direct or Indirect communication
2. Synchronous or asynchronous communication
3. Automatic or explicit buffering

Direct Communication

Under direct communication, processes must explicitly name the sender or receiver in the communication.

The send() and receive() are defined as:

send(P, message) - send a message to process P
receive(Q, message) - receive a message from process Q

The communication link in direct communication has the following properties:

  • The link is established automatically. Processes need each other’s identity to send messages.
  • A link is associated with exactly two processes.
  • Between two processes, there is only one link.

There is a symmetry in addressing. In asymmetrical addressing, the sending process needs to address the receiver, but the recipient does not need to address the sender.

Direct Messaging
Figure 1 – Direct Messaging

Example of messaging with receiver does not need address of sender.

send(P, message) - send message to P
receive(id, message) - receive message from any process. Id is replaced with name of the sender process.

The disadvantage in symmetric and asymmetric schemes is in changing the identifier of a process. We need to change all the other process definitions and references to the old identifier and replace with the new one.


Indirect Communication

In indirect communication, messages are sent and received from mailboxes or ports. The processes can place messages into a mailbox or remove messages from them. The mailbox has a unique identification.

Two processes can communicate only if they have a shared mailbox.

send(A, message) - send a message to mailbox A
receive(A, message) - recieve a message from mailbox A

In this scheme, a communication link has the following properties:
1. A link is established between a pair of processes only if both have a same shared mailbox.
2. A link may be associated with more than two processes.
3. There may be different links, with each link corresponding to one mailbox, between pair of communicating processes.

Example: P1, P2 and P3 all share mailbox A. P1 sends message to A, while P2 and P3 execute a receive() from A. Which process will receive the message? The answer depends on one of the chosen method given below:

  • Allow link to associated with at-most 2 processes.
  • Allow at-most 1 process to execute receive() operation.
  • Choose randomly at-most one process to receive message or choose an algorithm to receive messages such as round-robin(each process take turn to receive message).

The mailbox may be owned either by a process or by the OS.

Indirect Messaging
Figure 2 – Indirect Messaging

If process owns (mailbox part of process address space) then:

  • Distinguish between owner(can only receive through own mailbox), and
  • the user (can only send messages to the mailbox).
  • When process with mailbox terminates, mailbox disappears, and all other processes should be notified.

If OS owns the mailbox, then:

  • It is independent process, not attached to a process.
  • Then the OS must allow the process to:

1. create a mailbox.
2. send and receive messages through mailbox.
3. delete the mailbox.

  • Process becomes the owner of new mailbox by default.
  • Owner process can only receive messages through this mailbox.
  • Ownership and receiving privileges can be passed using system calls to other processes.This will result in multiple receivers for each mailbox.

Synchronous and Asynchronous Communication

Communication happens using send() and receive(). There are many options for these two primitives. Message passing may be blocking or non-blocking also known as synchronous and asynchronous.

  • Blocking send – sending is blocked, until a message is received by receiving process or mailbox.
  • Non-blocking send – sending process sends the message and resumes operation.
  • Blocking receive – receiver blocks until a message is available.
  • Non-blocking receive – the receiver retrieves either a valid message or a null.

Automatic and Explicit Buffering

The messages exchanged between communicating processes resides in a temporary queue. The queue can be implemented in three way:

  1. Zero capacity – with zero capacity the link cannot have messages waiting. Blocking send is the correct option.
  2. Bounded capacity – the queue is of finite length n. If queue not full, sender can continue to send messages. If full, blocking send.
  3. Unbounded capacity – Infinite queue length; any number of messages wait and sender never blocks.

Zero capacity is called no buffering and other systems called automatic buffering.


  • Abraham Silberschatz, Peter B. Galvin, Greg Gagne (July 29, 2008) Operating System Concepts, 8 edn., : Wiley.
  • Tanenbaum, Andrew S. (March 3, 2001) Modern Operating Systems, 2nd edn., : Prentice Hall.
  • I.A.Dhotre (2008) Operating System, Second Edition edn., : Technical Publications.


Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.