What is inter-process communication?

The processes running on the computer system can be of two types:

  1. Independent process

  2. Co-operating process

The independent processes are not affected by other processes' execution, but the co-operating processes can be affected because they depend on other processes. Generally, we can think that independent processes are efficient, but co-operating functions can enhance speed and modularity in many situations.

In this answer, we'll learn how the co-operating process communicates with each other.

Inter-process communication

The inter-process communication is the methodology that allows processes to communicate with each other and synchronize their actions. This communication between the processes can also be called a method of cooperation between processes.

Advantages of IPC

There are several reasons for providing such a mechanism that allows process cooperation:

  • Convenience: This allows a single user to work on many tasks simultaneously; for instance, the user can edit or compile the file simultaneously.

  • Modularity: It's easier to work on a modular system by dividing an extensive system's functions into small processes or threads.

  • Computation speedup: If we want our program to run quickly, we must break it into smaller modules where each executes simultaneously with other modules, and for that, we need IPC.

  • Information sharing: Co-operating processes depend on other processes as well. The different processes may be interested in using the same data. IPC allows us to access the data concurrently.

Approaches to IPC

There are different approaches available to implement the environment of inter-process communication:

Pipes

A pipe is a uni-directional data channel. It's a half-duplex method where two pipes can be used for two-way data transmission between two processes. Pipes is the mostly used for communication between related processes that use the standard input-output method.

Message queues

Message queues are another approach for inter-process communication maintained by the OS that allows processes to communicate with each other without being connected by reading or writing to the message queue.

Note: The interval for storing messages in the queue is until the recipient retrieves them.

FIFO

The FIFO mechanism is used when two unrelated processes need to communicate. It's a full-duplex that allows both co-operating processes to communicate. In FIFO, one process sends the message first to another while the other waits for its turn and vice versa.

Direct communication

In direct communication, all the processes must name each other explicitly. A link is established between the two co-operating processes, and every pair can have one link at max.

Indirect communication

In indirect communication, the communication link is only established when the co-operating processes share a standard mailbox. It means there might be several links between processes. Similarly, a single link can also communicate with multiple processes.

Note: In indirect communication, the link may be uni-directionalMoving or operating in a single direction. or bi-directional.Moving, or taking place in two usually opposite directions

Other approaches are available, like IPC implementation through sockets, files, and signals, but let's briefly discuss the primary models of IPC.

Primary models of IPC

We have studied various implementations for IPC, but the co-operating process requires an efficient message exchange mechanism. There are the following two primary models used for efficient inter-process communication:

Message passing mechanism

In this mechanism, communication occurs by exchanging messages among the peer processes. The process communicates with each other without involving any extra shared memory or variables. To communicate, the process develops a communication link first and starts exchanging messages using two primitives:

  • Send (message)

  • Receive (message)

Shared memory mechanism

In this mechanism, the OS establishes and maintains a part of memory shared by all co-operating processes. The peer processes can exchange messages by reading and writing the data into a shared region. It requires sharing some variables, which entirely depends on the programmer's implementation. Let's look at the figure below:

Copyright ©2024 Educative, Inc. All rights reserved