Unit 3 - INTER PROCESS COMMUNICATION AND SYNCHRONIZATION(Part-II)

 

Unit 3 - INTER PROCESS COMMUNICATION AND SYNCHRONIZATION

Deadlock, Deadlock Characterization, Necessary and Sufficient Conditions for Deadlock, Deadlock Handling Approaches: Deadlock Prevention, Deadlock Avoidance and Deadlock Detection and Recovery. Concurrent and Dependent Processes, Critical Section, Semaphores, Methods for Inter-process Communication; Process Synchronization, Classical Process Synchronization Problems: Producer-Consumer, Reader-Writer.

 

 

 

Inter Process Communication:

Inter-process communication or interprocess communication (IPC) refers specifically to the mechanisms an operating system provides to allow the processes to manage shared data. Interprocess Communication or IPC provides a mechanism to exchange data and information across multiple processes, which might be on single or multiple computers connected by a network.

Why IPC is required?

IPC helps achieve these things:

  • Computational Speedup
  • Modularity
  • Information and data sharing
  • Privilege separation
  • Processes can communicate with each other and synchronize their action.

Approaches for Inter-Process Communication

 

Methods of InterProcess Communication(IPC):

There are several different ways to implement IPC. IPC is set of programming interfaces, used by programs to communicate between series of processes. This allows running programs concurrently in an Operating System. Below are the methods in IPC:

Pipes

Pipe is widely used for communication between two related processes. This is a half-duplex method, so the first process communicates with the second process. However, in order to achieve a full-duplex, another pipe is needed.

Write() à à

                                                         |

                                                          \/

Read() ß ß

Message Passing:

It is a mechanism for a process to communicate and synchronize. Using message passing, the process communicates with each other without resorting to shared variables.

IPC mechanism provides two operations:

  • Send (message)- message size fixed or variable
  • Received (message)

             Process A

            Process B

            

        Message Queue

M0

M1

M2

M3

Mn

              Kernel

 

Message Queues:

A message queue is a linked list of messages stored within the kernel. It is identified by a message queue identifier. This method offers communication between single or multiple processes with full-duplex capacity.

Direct Communication:

In this type of inter-process communication process, should name each other explicitly. In this method, a link is established between one pair of communicating processes, and between each pair, only one link exists.

Indirect Communication:

Indirect communication establishes like only when processes share a common mailbox each pair of processes sharing several communication links. A link can communicate with many processes. The link may be bi-directional or unidirectional.

Shared Memory:

Shared memory is a memory shared between two or more processes that are established using shared memory between all the processes. This type of memory requires to protected from each other by synchronizing access across all the processes.

 

             Process A

             Shared Memory

             Process B

  

 

 

              Kernel

 

 

FIFO:

Communication between two unrelated processes. It is a full-duplex method, which means that the first process can communicate with the second process, and the opposite can also happen.

 

  • Definition: Inter-process communication is used for exchanging data between multiple threads in one or more processes or programs.
  • Pipe is widely used for communication between two related processes.
  • Message passing is a mechanism for a process to communicate and synchronize.
  • A message queue is a linked list of messages stored within the kernel
  • Direct process is a type of inter-process communication process, should name each other explicitly.
  • Indirect communication establishes like only when processes share a common mailbox each pair of processes sharing several communication links.
  • Shared memory is a memory shared between two or more processes that are established using shared memory between all the processes.
  • Inter Process Communication method helps to speedup modularity.
  • A semaphore is a signaling mechanism technique.
  • Signaling is a method to communicate between multiple processes by way of signaling.
  • Like FIFO follows FIFO method whereas Unlike FIFO use method to pull specific urgent messages before they reach the front.

 

 

Process Synchronization

          What is Process Synchronization?

            Classical Process Synchronization Problems

            Producer – Consumer Problem

            Reader – Writer Problem

 

 

What is Process Synchronization?

              Processes Synchronization or Synchronization is the way by which processes that share the same memory space are managed in an operating system. It helps maintain the consistency of data by using variables or hardware so that only one process can make changes to the shared memory at a time.

For example: A process A tries changing data in a particular memory location. At the same time another process B tries reading data from the same memory location, It is necessary that processes are synchronized with each other as it helps avoid the inconsistency of shared data.

 

Where can Process Synchronization can be done on - TeachingBee

 

 

The classical synchronization problems are as follows:

·         Bound-Buffer problem.

·         Sleeping barber problem.

·         Dining Philosophers problem.

·         Readers and writers problem.

 

 

 

Bounded Buffer problem is also called producer consumer problem. This problem is generalized in terms of the Producer-Consumer problem. Solution to this problem is, creating two counting semaphores “full” and “empty” to keep track of the current number of full and empty buffers respectively. Producers produce a product and consumers consume the product, but both use of one of the containers each time. 

Producer Consumer Problem - InterviewBit

 

 

Solutions for Producer – Consumer Problem / Bound and Buffer Memory:

Using Semaphore

A Semaphore S is an integer variable that can be accessed only through two standard operations : wait() and signal(). 
The wait() operation reduces the value of semaphore by 1 and the signal() operation increases its value by 1. 

 

wait(S){

while(S<=0);   // busy waiting

S--;

}

signal(S){

S++;

}

Using Monitor

Monitors are a synchronization construct,  Monitors are easy to implement than semaphores. The Monitor is a package that contains shared data structures, operations, and synchronization between concurrent procedure calls.

 

Atomic Transaction

Atomic Transaction (read – modify – write) on shared variable will be avoided.  Two count variables must be updated by every process at each and every Transaction.

 

The Dining Philosopher Problem states that K philosophers seated around a circular table with one chopstick between each pair of philosophers. There is one chopstick between each philosopher. A philosopher may eat if he can pickup the two chopsticks adjacent to him. One chopstick may be picked up by any one of its adjacent followers but not both. This problem involves the allocation of limited resources to a group of processes in a deadlock-free and starvation-free manner. 

Lightbox

 

Reader – Writer Problem

Suppose that a database is to be shared among several concurrent processes. Some of these processes may want only to read the database, whereas others may want to update (that is, to read and write) the database. We distinguish between these two types of processes by referring to the former as readers and to the latter as writers. Precisely in OS we call this situation as the readers-writers problem. Problem parameters: 

·         One set of data is shared among a number of processes. 

·         Once a writer is ready, it performs its write. Only one writer may write at a time.  

·         If a process is writing, no other process can read it.  

·         If at least one reader is reading, no other process can write.  

·         Readers may not write and only read.

 

https://image4.slideserve.com/1410608/classical-problem-2-the-readers-writers-problem-l.jpg

 

 

Barber shop Problem – A Barber shop with one barber, one barber chair and N chairs to wait in. When no customers the barber goes to sleep in barber chair and must be woken when a customer comes in. When barber is cutting hair new customers take empty seats to wait, or leave if no vacancy. 

 

Lightbox

Important questions

1 marks.

1.  -------------------------------- is the condition where the processors waiting for a resource which is being assigned to some other processor- deadlock condition

2. ------------------------------ is the Deadlock detection algorithm. – The Banker’s algorithm

3. ---------------------- in Deadlock condition is preventing the process to hold one or more resources while other processes are waiting for the resources. – hold and wait

4. Bounded Buffer problem is also called ------------------------. Producer and consumer problems.

5.  ------------------is a signaling mechanism technique. semaphore

2 marks.

1. Classify the deadlock conditions.

2. Generalize the process synchronization?

3. Classify the process synchronization methods.

4. Deadlock prevention methods

5. what is message passing

15 marks

1. Deadlock Condition and Deadlock Avoidance with neat diagram

2. Inter Process Communication(IPC) with all necessary 


 

1. Discuss in detail about Deadlock Condition and Deadlock Avoidance with necessary diagrams.

2. Summarize all the concepts of Process Synchronization with diagrams.

3. Discuss in detail about Inter Process Communication(IPC) with all necessary diagrams.

4. Summarize all the concepts of classical Synchronization process with neat diagrams.

      5. Bound-Buffer problem. Sleeping barber problem. Dining Philosophers problem. Readers and                    writers problem.

 

 

 

Comments

Popular posts from this blog

Computer Networks

Unit 1 - Introduction to Operating Sytem & Unit 2 - Process Characterization

UNIT I INTRODUCTION TO DEEP LEARNING