Unit 2InterprocessCommunication
Unit 2InterprocessCommunication
Interprocess Communication
Interprocess Communication
Inter Process Communication (IPC) refers to a
mechanism, where the operating systems allow various
processes to communicate with each other.
Processes should communicate in a well structured way
not using interrupts
Three issues need to be taken care of:
◦ How one process can pass information to another
◦ Making sure two or more processes do not get in eachother’s way
◦ Proper Sequencing when dependencies are present
Race Conditions
A race condition is an undesirable situation that
occurs when a device or system attempts to
perform two or more operations at the same time,
but because of the nature of the device or system,
the operations must be done in the proper
sequence to be done correctly.
Interprocess Communication
Race Conditions
4
Critical Regions (1)
6
A solution to critical section problem must satisfy
following three requirements:
wish to enter their critical sections, then only those processes that are not
executing in their remainder section can participate in deciding which will enter
Bounded Waiting: A bound must exist on the number of times that other
processes are allowed to enter their critical sections after a process has made a
request to enter its critical section and before that request is granted.
In this section we will examine different proposals for
achieving Mutual Exclusion
Disabling Interrupts
Lock variables
Strict Alternation
Peterson’s solution
The TSL Instruction
Disabling Interrupts
Its is the simplest solution on a single
processor System
Each process should disable interrupts just
Critical region
Disadvantage:
; ;
11
Peterson’s solution
TSL Instruction
Producer-Consumer Problem
The problem describes two processes,
the producer and the consumer, who share a
common, fixed-size buffer used as a queue.
The producer's job is to generate data, put it
into the buffer, and start again. At the same
time, the consumer is consuming the data
(i.e., removing it from the buffer), one piece
at a time.
Sleep and Wakeup
Signal(S) {
S++;
}
Semaphores
18
Monitors (1)
Example of a monitor
19
Monitors (2)
Philosophers eat/think
Eating needs 2 forks
Pick one fork at a time
How to prevent deadlock
23
Dining Philosophers (2)
24
Dining Philosophers (3)