Chapter 2 Process MGMT
Chapter 2 Process MGMT
• Process Concept
• Process Scheduling
• Operations on Processes
• Cooperating Processes
• Interprocess Communication
• Communication in Client-Server
Systems
• Operations on processes
• Process Synchronization
counter++;
counter--;
must be performed atomically.
• Atomic operation means an operation that
completes in its entirety without interruption.
• Bounded-Buffer Problem
• Dining-Philosophers Problem
do {
…
produce an item in nextp
…
wait(empty);
wait(mutex);
…
add nextp to buffer
…
signal(mutex);
signal(full);
} while (1);
do {
wait(full)
wait(mutex);
…
remove an item from buffer to nextc
…
signal(mutex);
signal(empty);
…
consume the item in nextc
…
} while (1);
Initially
wait(wrt);
…
writing is performed
…
signal(wrt);
wait(mutex);
readcount++;
signal(mutex);
…
reading is performed
…
wait(mutex);
readcount--;
signal(mutex):
• Shared data
semaphore chopstick[5];
Initially all values are 1
Operating System Concepts
• Five philosophers sit around a circular table. Each
philosopher spends his life alternatively thinking and
eating. In the centre of the table is a large plate of food. A
philosopher needs two chopsticks to eat a food. As there
are only 5 chopsticks available, one chopstick is placed
between each pair of philosophers and they agree that
each will only use the chopstick to his right and left.
• When he gets hungry, he picks up two chopsticks and eat
for a while. After a philosopher finishes eating he puts
down the chopsticks and starts to think.
• This problem is considered a classic synchronization
problem. It is a simple representation of the need to
allocate several resources among several processes in
deadlock free and starvation free manner.
Operating System Concepts
• Solution to the dining philosopher problem is with
semaphores.
i) A hungry philosophers executes wait() operation
to grab a chopsticks.
ii)After eating is finished, philosopher executes
signal() operation to release chopsticks.