Interprocess communication takes place between the cooperating processes. These processes communicate with each other by sharing data and information.
Although there occur some issues while establishing interprocess communication. We will discuss those issues along with their solution. We will also discuss ways to achieve interprocess communication.
Content: Interprocess Communication in Operating System
- What is Interprocess Communication (IPC)?
- Need for Interprocess Communication
- Issues in Interprocess Communication
- Methods of Interprocess Communication
Define Interprocess Communication (IPC)
Interprocess communication is communication between two processes that may be on the same system or on a different system. If we talk about the process in the operating system, they are of two types:
- Independent Process
- Cooperating Process
An Independent process is one that doesn’t get affected by the other processes running in the system. It doesn’t even affect the processing of any other process in the system. This is because the independent process doesn’t share any data with the other process.
The cooperating process is one that shares data with the other processes in the system. Thus, it can get affected by the other processes of the system. And even it can affect the working of other processes.
Need of Interprocess Communication
The cooperating process shares its data and information with the other processes. The reason behind this interprocess communication is:
- Information Sharing
Several processes may need to access the same piece of information. The mechanism of IPC allows different processes to share the same information concurrently.
- Computation Speedup
Small computations execute faster. Thus, if you want to execute a certain task faster. Then break the task into smaller sub-tasks. Now the interprocess communication mechanism lets these subtasks run in parallel.
But to speed up such tasks, the system must have multiple processing elements. Such as multiple processing units or I/O channels.
The interprocess communication mechanism allows the construction of a modern system. Where the functions of the system can be divided into separate processes and threads.
A computer user can perform several tasks simultaneously. Such as editing a document, printing a document, playing music etc.
Issues in Interprocess Communication
The issues related to interprocess communication are as below:
- How the two cooperating processes can exchange data or information.
- None of the communicating processes must come in each other way while executing.
- If there is dependency among the processes. Then the operating system must perform proper sequencing.
These are the three generic issues that processes face during interprocess communication.
The same sort of problems or issues arises in the case of threads. As the same problems exist for processes and threads. The same solutions are applicable to them.
Methods of Interprocess Communication
There are two methods or two models that operating systems can implement to achieve IPC.
- Shared Memory
- Message Passing
Some operating systems implement both of these models. Let us study these models in more detail.
Shared Memory System
The operating system implementing the shared memory model is a shared memory system. Here a cooperating process creates a shared memory segment in its address space. Now, if there occurs another process that wants to communicate with this process. Then it must attach itself to the created shared memory segment.
The communicating processes share information by:
- Writing data to the shared region
- Reading from the shared region.
Note: Operating system does not allow a process to access the memory of other processes.
But in a shared memory system, the process can access the memory of other processes. If two or more processes are ready to remove this restriction.
The format of the data to be shared and its location are totally under the control of the processes. The communicating processes must not write to the same shared location at the same time.
How the shared memory system resolves the issues of interprocess communication?
To understand this, let us discuss the producer-consumer problem. This is the most common paradigm for reflecting the issue of cooperating processes.
The producer-consumer problem state that:
There is a producer process, a consumer process and a fixed-size buffer.
- This buffer is in the critical section, which means only one process can access the buffer at a time.
- Here the producer can produce data only if the buffer is not full.
- And the consumer can consume data only if the buffer is not empty.
The buffer should be in a shared memory region of producer and consumer processes to resolve the issue. This allows the producer and consumer processes to access the buffer concurrently.
Thus, the producer process can produce the data onto the buffer. And at the same time, the consumer process can consume the data from the buffer. Along with this, both the producer and consumer processes must be synchronized. So that the consumer should not try to consume the data that the producer process has not yet produced.
Message Passing System
The message-passing system lets the cooperative processes communicate through a message-passing facility.
The message-passing system is more useful in the distributed environment. As in the distributed environment, the communicating processes may be running on different systems. And these systems are connected via a network.
The message-passing system facilitates communication via at least two operations. That sends messages and receives messages. Although the size of the message can be variable, or it can be of a fixed size.
With the fixed-size messages, the system-level implementation becomes simple. But the programming of such a system becomes difficult.
With the variable size messages, the system-level implementation is difficult. But the programming of such a system becomes simpler.
The message passing can either be:
Synchronous Message Passing System
In synchronous message passing, the sender is blocked until the receiver receives the message. And the receiver is blocked until the message is available.
Asynchronous Message Passing System
In asynchronous message passing, the sender sends a message and resumes its operation. Whereas the receiver may receive a valid message or a null.
Thus, the synchronous message passing achieves synchronization between the communicating processes. Which is an essential part of any interprocess communication.
So, this is all about interprocess communication. We have discussed the need for IPC and issues that occurred in IPC. And two models that the operating system can implement to achieve IPC.