Inter Process Communication In Operating System

In this tutorial, we will go through an overview of inter process of communication in operating system. We will see different types of processes, advantages of inter process communication, different techniques in inter process communication – (a) shared memory and (b) message passing. We will go through shared memory and message passing in detail. At last, we will see different scenarios where inter process communication is used.

Inter Process Communication is a mechanism which allows processes to communicate with each other and synchronize their actions. Whatever process is present in the system, they can communicate with each other. It is a method of cooperation.

There are two types of processes –

  1. Independent Process: An Independent process is not affected by other executing processes.
  2. Cooperating Process: A Cooperating process can be affected by other executing processeses.

For inter process communication, it is compulsory that all the processes are cooperating processes.

Why do we use inter process communication ?

Some of the benefits of using inter process communication are –

  1. Information Sharing: Multiple processes can share same information to perform some tasks. In such scenarios, inter process communication helps. There may be a scenario when a process needs to access remote process. In such case, this method of communication helps.
  2. Resource Sharing: We can do with the help of inter process communication.
  3. Communication speed: Computational speed will also increase if inter process communication method is used to communicate between processes.
  4. Modularity: An architecture is break down into different cooperating modules to increase the efficiency. All the modules cooperate using inter process communication method.

Processes can communicate with each other by using two ways –

  1. Shared Memory
  2. Message Passing

1. Shared Memory

Shared memory is an efficient way to share data between processes. One process will create a memory portion which other processes can access if allowed.

Let’s take an example to understand inter process communication using shared memory –

Assume that there are two processes –
Process A and Process B.

Both processes communicate using shared memory as shown below.

Tutorialwing Shared Memory Example of operating system

Shared Memory Example

There are two parts (a) and (b). Both represent shared memory techniques.

Image (a):
Process A generate information about certain resources and keeps records in shared memory. When process B needs to use that information, it will check the record stored in shared memory and take note of the information generated by process A and act accordingly. Thus, processes can use shared memory for extracting information as a record from other process as well as for delivering any specific information to other process.

Image (b):
Whenever process A uses some shared memory, it sends information to the kernel (operating system). When process B wants to perform some operation, it first checks the Kernel if any other device is using that resources or not. If any process is using that resource, it will take other resources which is free.

2. Message Passing

In message passing, there is no use of shared memory. If two processes A and B want to communicate with each other, at first, they establish a communication link. After this, they can start exchanging messages using basic primitives.
They need atleast 2 basic primitives –
(a) Send (message, destination) or Send(message)
(b) Receive (message, host) or Receive(message)

A standard message has two parts –
(a) Header
(b) Body

Header contains message type, source id, destination id, message length and control information. Control information contains sequence number, priority, action to do if runs out of space etc.

Body contains the actual message.

Generally, any message is sent using FIFO style.

Tutorialwing operating system inter process communication

IPC example

In this call, the sender and receiver processes address each other by names.

Mode of communication between two processes can take place in two ways:

  1. Direct Addressing
  2. Indirect Addressing

1. Direct Addressing of Message Passing

In this type, the two processes need to know the name of each other to communicate. This become easy if they have the same parent.

If process A send message to process B, then, basic primitives will be –

Send (B, message);

Receive (A, message);

Tutorialwing operating system Direct Addressing Example of message passing

Direct Addressing Example

At first, Processes A and B establish a communication links. Then, they start sending messages. In this example, process A is sending message to process B. So, it will send Send(B, message). In other case, if process A wants to receive message, it will receive using basic primitives Receive(A, message).

A link is established automatically between every pair of process that want to communicate. Process only need to know each other’s identity. In this type, link is associated with exactly two processes. Usually link is bidirectional but it can be unidirectional. Here, receiver knows the identity of sender. This type of direct communication is known as symmetric addressing.

Asymmetric addressing: In this type, only sender will name receiver for sending the message. There is no need for receiver to name the sender for receiving the message. This addressing is also known as asynchronous addressing.

Tutorialwing operating system Asymmetric Addressing Example of inter process communication

Asymmetric Addressing Example

Here, processes A and B are communicating through Asymmetric Addressing. Note that Process A is sending message using Send(B, message) but receiving message using Receive(message) instead of Receive(A, message).

2. Indirect Addressing of Message Passing

In this addressing, message is sent and received using a mailbox. A mailbox can be abstractly viewed as an object into which message may be placed. Message may be extracted by a process.

In this type, sender and receiver processes should share a mailbox to communicate.

Tutoriawing operating system Indirect Addressing Example of inter process communication

Indirect Addressing Example

Below are the types of communication link made through mailbox:

  1. One to one link: One sender wants to communicate with one receiver. So, only one link will be established.
  2. Many to one link: Multiple senders want to communicate with single receiver. Example: In client-server system, there are one server process and many client processes. Here, mailbox is known as a port.
  3. One to Many link: One sender wants to communicate with multiple receivers. That is broadcasting a message.
  4. Many to Many link: Multiple senders want to communicate with multiple receivers.

Examples of Inter Process Communication

Some examples of Inter process communication are –

  • Posix: It uses shared memory method.
  • Windows XP: It uses message passing method.
  • Mach: It uses message passing method.
  • Pipes
  • Server

Leave a Reply