Transcript for:
Understanding Inter-Process Communication (IPC)

In this lecture, we will be studying about inter-process communication. So, inter-process communication means the way in which processes communicate with each other. So, we know that there are different processes running in our systems and these processes may need to communicate with each other. So, the way the processes communicate with each other is known as inter-process communication. Now, processes executing concurrently in the operating system may be either independent processes or cooperating processes. Now in the operating system, we have two or more processes that are executing concurrently, which means they are executing at the same time. So, when two or more processes are executing at the same time in the operating system, these processes may either be independent processes or cooperating processes. So, first let us see what is the meaning of independent processes and what is the meaning of cooperating processes. So, independent processes are those processes which cannot affect or be affected by the other processes executing in the system. So, if we say that the processes are independent, that means that these processes cannot affect or cannot be affected by other processes executing in the system. So, all the processes may execute in their own ways and these independent processes are not affected by other processes and also they cannot affect other processes in the system. And then we have cooperating processes. These processes are the processes that can affect or be affected by the other processes executing in the system. So, cooperating processes are those processes which can affect the other processes in the system and also they can be affected by other processes executing in the system. So, an example of this cooperating processes are any process that shares data with other process. So, if one process is sharing data with another process, then we can say for sure that that process can affect the other process with which it is sharing the data. So, if two processes are sharing data, then those two processes will be affected by each other. So, those kind of processes are known as cooperating processes. So, if they are independent processes, they are not sharing anything and they are executing in their own ways and they are not affected by each other. So, that is what we mean by independent processes and cooperating processes. Now, if you look at this, we can see that inter-process communication will be required in cooperating processes. Because in cooperating processes, they are going to be affected by each other and they may need to communicate with each other. So, mostly in the case of cooperating processes, we are going to need this inter-process communication. Now, There are several reasons for providing an environment that allows process cooperation. So, we may have several reasons why we need to allow processes to cooperate with each other. And let's see what are those. So, the first one is information sharing. So, in this information sharing, what we mean is that several users may be interested in a single piece of information. For example, a shared file which we just saw before. So, when several users are interested in a single piece of information, We will have to provide an environment in which the information can be accessed concurrently. That means both the users or several users will be able to access that information at the same time. So, that is one reason why we need to provide an environment that allows process cooperation. Because the two users or the several users may be trying to access via different processes. So, these processes will need to communicate or cooperate with each other in order to provide this information sharing. Now, the next point is computational speedup. Now, in order to achieve computational speedup, what we can do is, if we are having a task, we will have to divide that task into several sub tasks. And all these sub tasks will be made to run concurrently. In that way, we can speed up our system. So, instead of taking one task and waiting for it to complete from the beginning till the end, What we can do is we can break it down into sub-task and all these sub-task will be running concurrently and hence we can achieve more speed in our system. Now, when we do that, when the task are broken down into several different task, they are assigned to several different processes. They become several different processes. Now, since all these processes belongs to one single task or to one main task, so those processes will need to communicate with each other. So, this is another reason why we need to allow the processes to cooperate with each other. So that we can achieve this computational speed up by breaking down the task into several different tasks and making them to run concurrently. Now, the next point is modularity. So, modularity means we want to design the system by dividing it into separate modules. So, when we are designing a system, one person is not designing the entire system. We divide the system into different modules and these modules will later be put together to work to achieve a single goal. So, when we want to achieve modularity, we are dividing the system into several different modules. And also these modules will need to communicate or cooperate with each other. So, this is another reason why we need to provide an environment that allows process cooperation in order to achieve modularity in our system. And then the next point is, convenience. So, if we allow the processes to cooperate with each other or if we provide an environment in which the processes can cooperate with each other, then that becomes very convenient for the user. For example, a user may be using a system and he may be doing several different tasks at the same time. He may be listening to music, he may be typing a document, or he may be printing a document at the same time. So, when he is doing all these things at the same time, There are different processes running at the same time. So, these processes are running concurrently and they need to cooperate with each other so that all the tasks can run smoothly without clashing with each other. So, convenience is another reason why we need to provide an environment that allows process cooperation. Alright, so these are the reasons why we need to provide an environment that allows process cooperation. Now let us see in what ways can we provide an environment that allows process cooperation. Or in what ways can we let the processes to cooperate or communicate with each other? How does the inter-process communication actually takes place? So, that is what we are going to see now. So, as I already told you, cooperating processes require an inter-process communication which is abbreviated as IPC mechanism that will allow them to exchange data and information. So, When the processes need to cooperate with each other, they need to communicate with each other. So, for that we require something known as inter-process communication or IPC, which will allow the processes to exchange data and information and hence they can have the communication between each other. And there are two fundamental models of inter-process communication. The first one is called shared memory and the second one is called message passing. Now let us see What are these two models of inter-process communication? And how do they differ from each other? And what do they actually mean? So, first of all talking about shared memory system. In the shared memory model, a region of memory that is shared by cooperating processes is established. And processes can then exchange information by reading and writing data to the shared region. So, in this shared memory model, what happens is that we established a region of memory that will be shared by the cooperating processes. So, there will be a portion of memory that can be shared by all the processes that are cooperating with each other. And what will happen? They will exchange information by reading and writing data to the shared region. So, whenever one process wants to communicate to another process, what it will do is, it will write the information or the thing that it wants to share or communicate to the other process into that shared memory region. And then the other process what it can do is it can read that data which was written by the first process from the shared memory region and then it will understand what it actually was trying to communicate. So, that is what happens in the shared memory models. And then the second one is message passing. So, in message passing model communication takes place by means of messages exchanged between the cooperating processes. So, in this message passing model what happens is that the communication between the processes, they take place via messages which the processes exchange between each other. So, there are messages which will help them in communicating with each other. So, these messages are exchanged between processes and that is how the communication takes place in the message passing model. So, these are the two fundamental models of inter process communication. Now, I'll take a diagram in order to explain this in a better way so that you can visualize how it actually happens. So, here we have two figures A and B. And the first figure, it represents the shared memory communication model. And then the second figure B, it represents the message passing communication model. So, if you look at this in the first figure A, which is the shared memory system, We have two processes, process A and process B, which will be cooperating to each other and which are trying to communicate to each other. And here in between we have the shared region of memory. So, when process A wants to communicate to process B, what it will do is, it will write the information that it wants to communicate to the shared memory region. And what process B will do is, it will read the information that was written to the shared memory region by process A and it will understand what communication was A trying to make. So, by the help of this shared memory region, process A was able to communicate to process B. So, whatever information process A put here, process B will be able to read it. So, process A writes here and process B reads from here. And it is possible because this is a shared memory region and it is accessible to both process A and process B. So, that will be the case even when there are more processes like this. So, this is the example of a shared memory communication model. Now, the next one that we have in figure B is a message passing communication model. So, in the same way, here we have two processes, process A and process B, which are trying to communicate to each other. And here we have the kernel and this M, they stand for the messages. So, when process A wants to communicate to process B, it will send the message to process B. And how will it send? It will create the message and the message will go to the kernel. So, the kernel will get the message and it knows that this message is for process B. So, the kernel will send this message to process B and process B gets the message. So, that is how the message flows in this message passing model. The process A sends the message to the kernel and the kernel sends the message to process B. So, that is the flow and in that way process A is able to communicate to process B via this message passing. So, that is how communication takes place in case of a message passing model. So, these are the two most common models of inter-process communication or IPC. First is the shared memory and another one is the message passing. So, these are very important topics in this operating system under the sub-topic of inter-process communication. So, I hope this was clear to you. Thank you for watching and see you in the next one.