 everyone. Today we are going to learn about cooperating processes. The learning outcome of this session are student will be able to define cooperating process concept and illustrate producer consumer problem. Let us recall what is process? As we know process is nothing but program in execution. Many type of processes execute concurrently in the system. So, there are two types of processes. Independent process and dependent process. Independent process cannot be effect or be affected by any other process. And these are the processes which do not share any of the information with any other process. Whereas dependent process which is also called as cooperating process share information with other processes and it can be effect or be affected by any other process executing in the system. So, cooperating processes share information with each other. Let us see the advantages of cooperating process. Cooperating process allows information sharing as many users require same type of information to be shared. So, cooperating process allows such type of information to be shared between many users. For example, file or variable. Computation speedup. Suppose we have a task which is to be executed in faster manner. Then that task can be divided into sub-task and that sub-task can be run in parallel to get the result faster. So, in this way the cooperating process support computation speedup. And communication between the processes allows to get the result from that sub-task and computation speedup can be achieved. Modularity. We want to design a system in modular fashion. So, cooperating process allows to design a system in modular fashion by making it more convenient. Making the system inconvenient means it makes user to make it easy to use and allow different type of information to be shared with each other. For cooperating process inter-process communication model is required. So, that inter-process communication model allows cooperating process to exchange information with each other. There are two fundamental model of inter-process communication. They are message passing system and shared memory. In message passing system the processes can communicate with each other by exchanging messages. While in shared memory the processes can communicate with each other by using a shared region. A part of memory is shared between the processes which wish to communicate with each other. And using that shared memory region process can exchange information with each other. Message passing system is useful for exchanging smaller amount of data. While shared memory is used to exchange information which may be in big amount and shared memory gives maximum speed and convenience and it is more faster than message passing system. Because message passing system is implemented using system calls. So, it is quite time consuming. While in shared memory system call is used to establish only shared memory region. Once the shared memory region is established there is no kernel intervention when process is communicating with each other. And that is why shared memory is more faster than message passing system. Let us see one example of cooperating process that is producer consumer process. In producer consumer process producer produces an item which is stored in a buffer and consumer has to consume that item from the buffer. For example compiler may generate assembly code that is consumed by a similar. A similar in turn may generate object code that in turn consumed by loader and there is one more example of producer consumer that is server and client. Where server produces an HTML files and images which is consumed or read by the client web browser by where the client has requested that pages to the server. So, server and client is also one example of producer consumer process. Producer and consumer process must be synchronized. The producer can produce one item while consumer is consuming another item. They must be synchronized so that the consumer does not try to consume an item that has not yet been produced by the producer process. Now just pause a video and just think that which communication model is required to implement producer consumer problem. Write down your answer. Let us see as we know there are two communication model message passing system and shared memory. So, to implement producer consumer problem shared memory is used. Shared memory is nothing but it is a buffer. Buffer is a region which is to be shared between producer and consumer. It is nothing but a shared memory which is shared between producer and consumer process. The size of the buffer must be fixed or unbounded. So, unbounded buffer places no limit on the size of the buffer where only consumer process will wait till there is no item in the buffer. But producer process will never wait because there as size of the buffer is not fixed producer process goes on producing an item. While in bounded buffer size of the buffer is fixed. So, in bounded buffer the consumer will wait if there is no item into the buffer and the producer will produce and producer will wait if buffer is full. Now let us see the bounded buffer producer consumer problem. The common data structure between producer and consumer process are shown here. We can see that buffer size is equal to 10 and it uses two variables that is in and out which points to the in points to the next free position in the buffer while out points to the first full position in the buffer as shown in the figure. Here we have buffer with size 10 and in and out both point to the first position into the buffer currently. Now let us see the producer process. This is the code which is to be executed by producer process. Now suppose we have a buffer with size 10. Now here initially value of in is equal to 0 and out is equal to 0. Now it will we will check the while loop while in plus 1 mod buffer size. As we know more gives remainder value of in is right now 0. So, 0 plus 1 that is 1 more buffer size is 10 1 mod 10 gives 1 value of out is 0. So, 1 equal to equal to 0 this condition is false because 1 is not equal to 0. As condition is false we can say that their buffer is not full there is a space in a buffer. So, producer process will produce an item at the first position into the buffer. So, we can see here the producer process produces an item a 1 into the buffer at position 0 and value of in is incremented while the value of out is as it is that is out it as position 0 and in is incremented. Once in is incremented again this file loop is checked 1 plus 1 mod 2 mod 10 which is 2 is not equal to 0. So, again the next item is produced into the buffer at next position. In this way this loop goes on continue and producer process will produce an item as shown in the figure in always in the next position. Whenever value of in is incremented the value is produced into the next position into the buffer. Now, when in reaches to the last position that is at position 9 again the while loop is checked that is here value of in is 9 and out is 0. So, in this case the it shows that buffer is full because 10 mod 10 is equal to 0 0 equal to equal to 0 means buffer is full. Now, in this full condition says that producer process should wait because there is no space into the buffer this is what the producer process. Now, let us see the consumer process initially there is no item into the buffer. So, here producer process will wait now suppose consumer process has to wait. Now, suppose we have a buffer with items produced by the producer process. So, in this case the value of out here at position 0 while in is at position 9. As in is not equal to out consumer process will consume an item out is equal to 0 that is next consume it will consume an item from the next position into the buffer and value of out is incremented as shown in the figure. So, out is incremented and each one by one item is consumed by the consumer process. Once the out consume all items and it reaches at the position 9 here in is equal to out is at position 9 which shows that all items are consumed and as in is equal to equal to out it shows empty buffer. So, producer process consumer process has to wait here consumer will wait. Now, the producer consumer synchronization suppose producer and consumer is executing simultaneously initially there is no item into the buffer. So, producer will produce item at position 0 and increment the value of in it will place an item a 2 into the buffer at the same time consumer process value of out is equal to 0. So, it will consume first item from the buffer and increment the value of out producer increment the value of in produces an item consumer simultaneously consuming an item in this way the producer and consumer are synchronized. So, synchronization must be there in producer and consumer problem. So, this is how the synchronization takes place these are the references thank you.