• Operating System Video Tutorials

Operating System - Inter Process Communication



Inter Process Communication (IPC)

Inter process Communication (IPC) is a mechanism which allows the exchange of data between processes. It enables resource and data sharing between the processes without interference. This communication involves a process letting another process know that some event has occurred or they has been data transfer between two or more processes.

A diagram that illustrates inter process communication is as follows −

Illustrates Inter Process Communication

Synchronization in Inter-Process Communication

Synchronization is a necessary part of inter-process communication. It is either provided by the inter-process control mechanism or handled by the communicating processes. Some of the methods to provide synchronization are as follows

1. 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.

2. 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.

3. Barrier

A barrier does not allow individual processes to proceed until all the processes reach it. Many parallel languages and collective routines impose barriers.

4. 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.

Why is Inter-Process Communication Necessary?

Inter-process communication is necessary in process management for a number of reasons, such as −

1. Information sharing

Inter-process communication is used for instruction sharing and several tasks and commands are performed in the computer by sharing the operating system to the task. The information is needed to be shared so that a task is performed.

2. Achieving Modularity

When a large task is broken into smaller modules, each of these modules is executed by one or more processes. As these processes are a part of a bigger task, they need to coordinate among themselves, share data and control signals to achieve the task. IPC helps in coordination among the processes and thus helps to achieve modularity.

3. Faster Processes

Properly synchronised inter-process communication helps processes to complete tasks faster resulting in overall speedup of the system.

4. Convenience

Individual users may work on many tasks at the same time and users may edit, listen to music and do all types of tasks at a time because the operating system is very convenient due to inter-process communication.

Approaches to Inter-Process Communication

The different approaches to implement inter-process communication are given as follows

1. Pipe

A pipe is a data channel that is unidirectional. Two pipes can be used to create a two-way data channel between two processes. This uses standard input and output methods. Pipes are used in all POSIX systems as well as Windows operating systems.

2. Socket

The socket is the endpoint for sending or receiving data in a network. This is true for data sent between processes on the same computer or data sent between different computers on the same network. Most of the operating systems use sockets for interprocess communication.

3. File

A file is a data record that may be stored on a disk or acquired on demand by a file server. Multiple processes can access a file as required. All operating systems use files for data storage.

4. Signal

Signals are useful in interprocess communication in a limited way. They are system messages that are sent from one process to another. Normally, signals are not used to transfer data but are used for remote commands between processes.

5. Shared Memory

Shared memory is the memory that can be simultaneously accessed by multiple processes. This is done so that the processes can communicate with each other. All POSIX systems, as well as Windows operating systems use shared memory.

6. Message Queue

Multiple processes can read and write data to the message queue without being connected to each other. Messages are stored in the queue until their recipient retrieves them. Message queues are quite useful for inter-process communication and are used by most operating systems.

A diagram that demonstrates message queue and shared memory methods of inter-process communication is as follows −

Demonstrates Message Queue and Shared Memory
Advertisements