Interprocess Communication in Operating System

FREE Online Courses: Dive into Knowledge for Free. Learn More!

Inter-process communication helps exchange data between multiple threads in one (or more) process or program. It doesn’t matter whether the process is running on single or multiple computers (connected by a network). It allows coordination of activities among various program processes running concurrently in an OS.

IPC in OS

This is a set of programming interfaces that allow a program to handle multiple user requests at the same time. As every user request results in multiple processes running in the OS, it is necessary for processes to communicate with each other. There are two types of communications:

  • First is between related processes. This is initiated by one process only, like parent and child processes.
  • Second is between unrelated processes. This can be between two or more different processes.

Synchronization in Interprocess Communication

Synchronization is an important part of IPC that is either handled by the communicating processes or provided by an interprocess control mechanism. Following are some methods that help provide synchronization:

  • Semaphore: This is a variable that controls access to a common resource through multiple processes and has two types namely, binary and counting.
  • Mutual Exclusion: In this, only one process thread can enter the critical section at a time. This prevents race conditions.
  • Barrier: It prevents individual processes from proceeding until all the processes reach it. Some parallel languages and collective routines are the ones that usually impose barriers.
  • Spinlock: A type of lock for which processes need to wait in a loop while checking if the lock is available or not. This waiting of processes is called busy waiting as processes are not performing any useful operation despite being active.

Approaches in Inter-Process Communication

Following are some important methods for interprocess communication:

Pipes: This half-duplex method allows communication between two related processes. A half-duplex method allows the first process to communicate with the second process. In order to achieve a full-duplex, we need to add another pipe.

Message Passing: It helps a process communicate and synchronize with each other without resorting to shared variables. IPC provides two operations on message passing, namely, sending a message of either fixed or variable size and receiving a message.

Message Queues: A linked list that stores messages in the kernel and is identified by a message queue identifier. It provides communication between one or many processes with full-duplex capacity.

Direct Communication: This requires processes to name each other explicitly. A single link is then established between a pair of communicating processes.

Indirect Communication: This is established when processes share a common mailbox. Each pair of processes can share multiple communication links. Similarly, one link can communicate with several processes and it can either be bi-directional or unidirectional.

Shared Memory: This is the shared memory between two or more processes, established using shared memory between all the processes. It requires protection from each process that can be achieved through synchronized access among processes.

FIFO: A full-duplex method where the first process can communicate with the second process, and vise-versa. This is communication between two unrelated processes.

Need of IPC

Following are the reasons we need IPC

  • Increases modularity.
  • It is computational.
  • Allows privilege separation.
  • Convenient to use.
  • Helps OS communicate with each other and in action synchronization.

Terms Used in IPC

Following are some terms in IPC:

  • Semaphores: This is a signaling mechanism that either allows or disallows access to resources. This depends on how it is set up.
  • Signals: This helps set up communication between multiple processes through signals. The destination process recognizes the signal sent by the source process by number and handles it accordingly.

Like FIFO vs Unlike FIFO

LIKE FIFOUNLIKE FIFO
Follows FIFO methodPulls particular urgent messages before they reach the front
Is independent of sending and receiving processesEver-ready, there is no need to open or close it
Data transfer among unrelated processesNo synchronization problems between open & close

Summary

IPC helps exchange data between multiple threads in one (or more) process or program. It is a set of programming interfaces that allow a program to handle multiple user requests at the same time. Following are the approaches of IPC:

  • Pipes
  • Message passing
  • Message queues
  • Direct communication
  • Indirect communication
  • Shared memory
  • FIFO

Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *