Operating System (203105203)
CHAPTER-3
Inter-Process Communication
Introduction To IPC
IPC refers to a mechanism which allows communication between two or
more processes to perform their actions simultaneously.
Processes that are executing concurrently in a program are of two types-
(i) Independent Processes:-These are those processes which does not
dependent on execution of other process in same program. Independent
processes don’t share data with another process.
(ii) Co-operating Processes:- These are the processes which can affect or
get affected by other processes during execution. Co-operating processes
can share data with another processes in simultaneous execution.
Why we need IPC?
There are several reasons which allows processes to co-operate:-
(i) Information sharing
(ii) Computation speedup
(iii) Modularity
(iv) Convenience
Race condition
Race condition is a situation arise due to concurrent execution of more
than one processes which are accessing and manipulating the same
shared data and the result of execution depends upon the specific order
where the access take place.
Race condition leads to inconsistency which is totally undesirable.
Reasons for Race Condition
1. Exact instruction execution order cannot be predicted
2. Resource (file, memory, data etc…) sharing.
Critical section
Critical section is piece of code which contains some shared code of
variable which is accessible by each process concurrently in order to
complete execution. There must be only one process is allowed at a
time in critical section otherwise more than one access may lead to
inconsistency. concurrent accesses to shared resources can lead to
unexpected or erroneous behaviour , so part
of the program where the shared
resource is accessed is protected.
This protected section is the
critical section or critical region.
Figure :1 [image source google ]
Need of critical section
Process A have to read variable ‘x’ and process B has to write to the
same variable ‘x’ at the same time
if A needs to read the updated value of
‘x’, executing Process A and Process B at
the same time may not give required
results. To prevent this, variable ‘x’ is
protected by a critical section. First, B
gets the access to the section. Once B
finishes writing the value, A gets the
access to the critical section and variable
‘x’ can be read.
Solution to critical section
Brute-Force approach by using
locking mechanism
Figure :2 [image source google ]
Monitor
?• A more elevated level synchronization primitive.
• A monitor is a bunch of techniques, variables, and information
structures that are completely assembled in an exceptional sort of
module or bundle.
• Procedures may call the strategies in a monitor at whatever point
they need to, however, they can't directly get to the monitor's
interior data structures from methodology announced outside the
monitor.
• Monitor have a significant property for accomplishing common
rejection: just one procedure can be dynamic in a monitor at any
moment.
• At the point when a procedure calls a monitor technique, the initial
hardly any directions of the method will verify whether some other
procedure is as of now dynamic inside the monitor .
• Assuming this is the case, the calling procedure will be suspended
until the different procedure has left the monitor. On the off
chance that no different procedure is utilizing the monitor, the
calling procedure may enter.
Producer and Consumer Problem..
Cont..
Semaphore and Bounded Buffer
Producer Consumer Problem.
Cont..
Reader & Writer Problem using
Semaphore
Dining Philosopher’s Problem
Cont..
Cont..
Reference
[1]
https://www.geeksforgeeks.org/dining-philosopher-problem-using-semaphores
/
www.paruluniversity.ac.in