Actions

Interprocess Communication (IPC)

Revision as of 20:32, 11 November 2021 by User (talk | contribs)

Official Definition: Interprocess communication (IPC) is used for programs to communicate data to each other and to synchronize their activities. Semaphores, shared memory, and internal message queues are common methods of interprocess communication.

What it means:
IPC is a method for two or more separate programs or processes to communicate with each other. This avoids using real disk-based files and the associated I/O overhead to pass information. Like a file, you must first create or open the resource, use it and close it. Like real files, the resources have an owner, a group, and permissions. Until you remove the resource it continues to exist. Unlike real disk-based files, semaphores, message queues and shared memory do not persist across reboots.[1]


Interprocess Communication
source: Tutorials Point


Synchronization in Interprocess Communication[2]
Synchronization is a necessary part of interprocess communication. It is either provided by the interprocess control mechanism or handled by the communicating processes. Some of the methods to provide synchronization are as follows −

  • Semaphore: A semaphore is a variable that controls the access to a common resource by multiple processes. The two types of semaphores are binary semaphores and counting semaphores.
  • Mutual Exclusion: Mutual exclusion requires that only one process thread can enter the critical section at a time. This is useful for synchronization and also prevents race conditions.
  • Barrier: A barrier does not allow individual processes to proceed until all the processes reach it. Many parallel languages and collective routines impose barriers.
  • Spinlock: This is a type of lock. The processes trying to acquire this lock wait in a loop while checking if the lock is available or not. This is known as busy waiting because the process is not doing any useful operation even though it is active.


Approaches to Interprocess Communication[3]
The different approaches to implement interprocess communication are given as follows − Pipes: Pipe is widely used for communication between two related processes. This is a half-duplex method, so the first process communicates with the second process. However, in order to achieve a full-duplex, another pipe is needed.

  • Message Passing: It is a mechanism for a process to communicate and synchronize. Using message passing, the process communicates with each other without resorting to shared variables. IPC mechanism provides two operations:
    • Send (message)- message size fixed or variable
    • Received (message)
  • Message Queues: A message queue is a linked list of messages stored within the kernel. It is identified by a message queue identifier. This method offers communication between single or multiple processes with full-duplex capacity.
  • Direct Communication: In this type of inter-process communication process, should name each other explicitly. In this method, a link is established between one pair of communicating processes, and between each pair, only one link exists.
  • Indirect Communication: Indirect communication establishes like only when processes share a common mailbox each pair of processes sharing several communication links. A link can communicate with many processes. The link may be bi-directional or unidirectional.
  • Shared Memory: Shared memory is a memory shared between two or more processes that are established using shared memory between all the processes. This type of memory requires to protected from each other by synchronizing access across all the processes.
  • FIFO: Communication between two unrelated processes. It is a full-duplex method, which means that the first process can communicate with the second process, and the opposite can also happen.


References

  1. What is Interprocess Communication (IPC)? IBM
  2. Synchronization in Interprocess Communication Tutorials Point
  3. Approaches to Interprocess Communication Guru99