Table of Contents
Interprocess communication is a capability of Operating Systems that enables a process to communicate with any other process. IPC enables one application to control another application and share the matching data without interfering with one another.
Let’s read further to learn more about interprocess communication, types of processes, different models of IPC, etc.
Interprocess communication (IPC) is an ability to hold by an Operating System that allows one process to communicate with another process. The processes can be running on the same computer or on different computers connected through a network.
Explore More:
Interprocess communication enables one application to control another application, and for numerous applications to share the matching data without interfering with one another. IPC is required in all multiprogramming systems.
But it is not generally supported by a single process Operating system such as DOS. The OS/2 and MS-Windows support an interprocess communication mechanism called Dynamic Data Exchange.
Interprocess communication is a mechanism that is used by the processes to exchange data and information. Many processes may be executed at the same time in the Operating System. These processes can be divided into two types known as independent processes and cooperating processes.
Following are the important types of processes
A process that cannot affect or be affected by any other process executing in the system is called an independent process. An independent process does not share data with any other process.
A process that can affect or be affected by any other process executing in the system is called a cooperating process. A cooperating process shares data with other processes.
Different advantages of process cooperation are as follows:
Process cooperation is necessary because many users may need to access the same information such as a shared file etc. an environment must be provided where such information can be accessed by multiple users concurrently.
One task can be divided into multiple tasks to execute it faster. All divided subtasks can be executed concurrently to speed up the computation. In this case, these subtasks may be required to cooperate with each other as they are part of the same task.
Process cooperation is very important if the system is to be constructed in the modular style. The modular system divides the functions into separate processes or threads.
Process cooperation provides convenience if a single user is working on multiple tasks at the same time. It ensures that any conflicts are avoided in the system if the user is using the same data in multiple tasks.
There are two fundamental models of interprocess communication:
The shared memory model establishes a region of memory that is shared by cooperating processes. The processes exchange information by reading and writing data to the shared region. This model is faster than a message-passing model and provides maximum speed and convenience.
Typically, the shared memory region resides in the address space of the process that creates this region. The other processes requiring to communication using that shared memory process to access the memory of another process.
All processes wishing to communicate using this model must agree to remove this restriction. The processes must also ensure that they do not write to the same location simultaneously.
Below is a very simple example of two cooperating processes. The problem is called the producer-consumer problem and it uses two processes called producer and consumer.
Both processes run parallel. If the consumer has nothing to use, it waits. There are two sides of the producer. In version one, the producer can produce an unlimited amount of items. This is called the Unbounded Buffer Producer-Consumer Problem.
In the other version, there is a predetermined limit to the buffer size. When the buffer is full, the producer must wait until there is some space in the buffer before it can make a new item.
Here is a shared memory resolution for a bounded buffer producer-consumer problem. Both processes have some collective data that can be accessed and updated. The shared data is as follows:
// shared data:
int n=5, item, in, out;
// number of items in a buffer is at most 5
Int buffer [n];
// both the consumer and producer are currently looking at buffer element 0.
In=0;
Out=0;
// Producer Process
While (true)
{
While (in+1 % n==out)
(
// Do nothing
)
//produce a random item
Buffer[in] = nextProduction;
In = in+1 % n;
}
// Consumer process
While (true)
{
While (in == out)
{
// Do nothing
}
NextConsumed = buffer [out];
Out = out + 1 % n;
}
The producer essentially just checks to see if there is any space in which to put a recently produced item (outer while loop). If there is no space, then it waits until there is a little space. The consumer waits while the buffer is empty.
If there is something, it captures the next item and consumes it. One drawback with this solution is that there is one element of the buffer that is wasted.
In the message-passing model, the cooperating processes communicate by exchanging messages with one another. This model is useful for exchanging a smaller amount of data. It can also be implemented more easily than a shared memory model.
It is typically implemented using system calls and is more time-consuming. The message-passing model is typically useful in a distributed environment. The processes may reside on different computers connected by a network.
The chat program used on the internet is an example of a message-passing system. Users can communicate by exchanging messages with one another. A message-passing model provides at least two operations:
Send (message)
Receive (message)
Two processes can communicate with each other by sending and receiving messages. This communication can take place by establishing a communication link between these processes.
Following are the important mechanisms for interprocess communication:
The processes that want to communicate must refer to each other using any method. It can be done using direct or indirect communication.
In Direct communication, each process that wants to communicate must name the sender or recipient of the communication. There are two schemes of direct communication known as symmetric communication and asymmetric communication.
Symmetric communication requires that both the sender and receiver process must name each other to communicate. In asymmetric communication, only the sender process must name the recipient. The recipient process does not need to name the sender process.
Send () and Receive () functions in symmetric communication are defined as follows:
Send (P, msg) is used to send the message msg to the process P.
Receive (Q, msg) it is used to receive the message msg by the process Q.
Send () and Receive () functions in asymmetric communication are defined as follows:
Send (P, msg) is used to send the message msg to the process P.
Receive (id, msg) it is used to receive message msg from any process. The variable id refers to the name of the process with which the communication has taken place.
The properties of the communication link in direct communication are as follows:
In-indirect communication, the message is sent and received from mailboxes or ports. A mailbox is an object used by the processes to store and remove messages. Each mailbox has a unique identification. Two processes can communicate using this method only if they have a shared mailbox.
A mailbox can be owned by a processor or the Operating System. If the mailbox is owned by a process then it disappears when that process is terminated.
The Operating System must provide a mechanism for the following:
Send () and Receive () functions in asymmetric communication are as follows:
Send (M, msg) is used to send the message msg to the mailbox M.
Receive (M, msg) it is used to receive the message msg from the mailbox M.
The properties of a communication link in indirect communication are as follows:
There are some problems with the mailbox system that occur when more than two processes share a mailbox. Suppose that process 1 sends a message to a mailbox that is shared with process 2 and process 3. Process 2 and process 3 both try to receive the message. Who will get it?
Some solutions to the above problem are :
The communication between different processes takes place through calls to send() and receive () functions. Different design options to implement each function include message passing by blocking or unblocking. These are also known as synchronous or asynchronous.
The message exchanged via any type of communication resides in a temporary queue. These queues can be implemented in the following ways:
The queue has a maximum length of zero. The link cannot have any messages waiting in it. The sender must wait until the recipient receives the message. The two processes must be synchronized for the transfer of a message. The zero-capacity link is referred to as a message-passing system without buffering.
The queue has a finite length of n. it can store n number of messages in it. A message is stored in the queue if it is not full and the sender continues the execution without any wait. The sender must block until there is a space available in the queue.
The queue length is infinite and any number of messages can wait in it. The sender is never blocked. That is why the sender is never delayed.
Having bad credit can make it challenging to obtain a personal loan, but it's not… Read More
Traveling doesn't have to break the bank. With some careful planning and smart strategies, you… Read More
Are you looking for a job in the fruit packing industry with the added benefit… Read More
Are you considering a move from the United States to Canada? Whether it's for a… Read More
A credit card is a financial tool that allows you to borrow money from a… Read More
Watching sports online for free can be challenging due to the licensing agreements and restrictions… Read More