Table of contents
1.
Introduction
2.
What is Interprocess Communication?
2.1.
Need for IPC
3.
Synchronization in Interprocess Communication
4.
Approaches for Inter-Process Communication
4.1.
FIFO
4.2.
Direct Communication
4.3.
Indirect Communication
4.4.
Shared Memory
4.5.
Message Passing
4.6.
Message Queues
4.7.
Pipes
5.
Various Other Techniques
5.1.
Sockets
5.2.
Signal
5.3.
File
6.
Frequently Asked Questions
6.1.
Which type of processes needs Interprocess communication?
6.2.
What is the most crucial feature of FIFO?
6.3.
Which IPC mechanism is the fastest?
7.
Conclusion
Last Updated: Mar 27, 2024

Interprocess Communication

Author Divyansh Jain
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?
Operating Systems

Introduction

Current computer systems allow us to do numerous tasks at once. Since multiple processes are running simultaneously, they often need to communicate with one another for various reasons.

Interprocess communication is the framework provided by the Operating System for allowing processes to interact with one another. This communication might include informing another process of an occurrence or data being transferred from one process to another.

Illustration Image

In this article, we’ll be walking through the concept of Interprocess communication in detail. Let’s get started: 

Also Read About, FCFS Scheduling Algorithm, Multiprogramming vs Multitasking

What is Interprocess Communication?

IPC is a method of sharing data across many threads in one or more processes or applications. The processes might execute on a single computer or on a network of machines but they are differentiated from one another. In order to communicate, they must follow some principles which we’ll be discussing later on in this article. 

Interprocess communication, as the name suggests, is a set of programming interfaces that allow a programmer to coordinate operations among several processes running simultaneously. This allows the system to manage a huge number of simultaneous user requests.

Since each user request may initiate many operating system processes, these processes may need to communicate with one another. Since each IPC protocol has its own set of pros and cons, it's not uncommon for a single piece of software to use all of them.

Need for IPC

There are two kinds of processes in the system:

  • Independent Processes
  • Cooperating Processes

 

Independent processes are those that do not affect or are affected by other processes in the system. In other terms, an independent process is one that does not exchange data with other processes.

Cooperating processes are those that can affect or are affected by other processes occurring in the system. In other terms, two or more cooperative processes share the same resources at the same time. Now, these resources could be a variable, memory, and so on. 

Inter-process communication is beneficial in the development of cooperative processes.

Let's look at some of the reasons why a process might need to communicate or exchange data with other processes. The following are some of the reasons:

  • Information Sharing: Multiple users may require access to the same piece of data (e.g., a shared file). As a result, an environment for concurrent access to shared information is required.
  • Computation Speedup: In order to speed up the execution of a task, tasks are often divided into multiple sub-tasks. This necessitates the use of linked processes to share task-related data.
  • Modularity: Most of the time, applications are broken into independent processes and created in a modular fashion. For example, each new tab in the Google Chrome web browser starts a new process.

Synchronization in Interprocess Communication

Synchronization is a phenomenon of coordinating the execution of processes in such a way that two processes cannot have access to the same common data and resources simultaneously. It is a method that is used to maintain the proper sequence of execution of cooperative processes.

Cooperating processes must interact and synchronize in order to cooperate. When processes communicate, synchronization is frequently required. Processes are carried out at unpredictable rates. Interprocess communication requires the use of synchronization. It's either handled by the communication processes or given by the interprocess control mechanism. The following are some of the synchronization methods:

  • Semaphore: A semaphore is a variable that regulates how many processes may access a shared resource. Binary and counting semaphores are the two types of semaphores.
  • Mutual Exclusion: Only one process thread can access the critical section because mutual exclusion is enforced. This helps with synchronization and avoids race conditions.
  • Barrier: A barrier usually prevents an individual process from moving forward until all other processes do not reach it. Many parallel languages employ it, and collective routines create obstacles.
  • Spinlock: As the name indicates, a spinlock is a form of lock. While attempting to acquire the spinlock, the processes wait or stay in a loop, verifying whether the lock is accessible or not. The process is characterized as busy waiting because, despite being active, it does not conduct any functional operations (or tasks).

Approaches for Inter-Process Communication

We'll now look at various approaches for processes to communicate with one another.

Inter Process Communication

FIFO

It is the communication between two separate( unrelated) processes. It's a full-duplex approach, which implies that the first process may communicate with the second process and vice versa.

Direct Communication

In this approach, a link is established between one pair of communicating processes, and only one link exists between each pair.

Indirect Communication

Indirect communication occurs when two processes share a shared mailbox, and each pair of processes has many communication links. Many processes can communicate through a connection. The link can be bidirectional or unidirectional.

Shared Memory

Shared memory is a memory that is shared across two or more processes. This permits data to be exchanged inside a specific memory region. Before data may access shared memory, semaphore values must be acquired. By synchronizing access across all processes, this form of memory must be guarded against each other.

Illsutration Image

It is the fastest way to communicate between processes. The operating system constructs a shared memory segment in RAM so that several processes may read and write to it. The processes share a memory area without using any operating system functions.

Message Passing

It is a communication and synchronization method for a process. The process communicates with each other through message passing rather than shared variables.

IPC mechanism provides two operations: 

  • Create a communication link(if not already). 
  • Begin exchanging messages with simple primitives. At the very least, we require two primitives:
    • Send (message) - message size variable or fixed. 
    • Received (message)

The message size might be fixed or variable. If it is constant in size, it is simple for an OS designer but difficult for a programmer. If it is variable in size, it is simple for a programmer but difficult for the OS designer. A typical message may be divided into two parts: the header and the body.

The header section contains information such as the message type, message length, destination id, source id, and control information. The control information includes information such as what to do if the buffer space runs out, the sequence number, and the priority. Messages are often transmitted in a FIFO manner.

Illsutration Image

When compared to the shared memory technique, message passing is slower. This is due to the fact that it uses system calls to communicate across processes.

Message Queues

In the kernel, a message queue is a linked list of messages. Messages can be sent between processes using a single queue or multiple message queues. The system kernel is in charge of this, and the messages are coordinated through an API. A message queue identifier is used to identify it. This approach allows full-duplex communication between single or many processes.

Pipes

Pipes are commonly used to communicate between two processes that are connected. This only permits data to flow in one direction. Similar to simplex systems (Keyboard). The data from the output is often delayed until it is received by the input process, which must have a shared origin. The first process interacts with the second since this is a half-duplex approach. On the other hand, a full-duplex connection requires the use of another pipe.

Various Other Techniques

Sockets

The socket is the network endpoint for sending and receiving data. This applies to data exchanged between processes on the same computer as well as data sent between various computers on the same network. Sockets are often used for interprocess communication in most operating systems. 

This approach is commonly used to communicate between a client and a server via a network. It enables a standard connection that is independent of the machine and operating system.

Signal

They are, as the name suggests, a form of signal that is utilized in interprocess communication in a minimum manner. Typically, they are system messages transmitted from one process to another. As a result, they are not utilized for data transmission but rather for remote instructions between various processes. They are often used to convey remote instructions rather than data between programs.

File

A file is a data record that can be saved on a disk or accessed by a file server on demand. A file can be accessed by several programs as needed. All operating systems use files to store data.

Check out this problem - Count Inversions

Must Read Evolution of Operating System

Frequently Asked Questions

Which type of processes needs Interprocess communication?

In general, there are two types of processes, Independent processes, and Cooperating processes. A process is considered independent if it has no effect on or is impacted by any other process running in the computer system. In contrast, a process is said to be a cooperating process if it can impact or is affected by other processes running in the computer system. The cooperating process needs interprocess communication as every process exchanges data with other processes. 

What is the most crucial feature of FIFO?

The first process may communicate with the second process and vice versa. Furthermore, it allows data flow between unrelated processes.

Which IPC mechanism is the fastest?

Shared memory is the fastest approach to interprocess communication. The major advantage of shared memory is that it eliminates message data copying. Semaphores are the most common technique for synchronizing shared memory access.

Conclusion

To summarize the article, we learned how cooperating processes need interprocess communication to communicate. And we also discussed the various approaches to performing interprocess communication and the needs of IPC. Hope you learned something. But the knowledge never stops, so to better understand the operating systems, you can go through many articles on our platform.

Recommended Readings:


Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, Uber, Microsoft, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Happy Learning Ninja :) 

Live masterclass