OS KCA203 Unit-2.1
OS KCA203 Unit-2.1
1. Problem Statement:
○ In concurrent systems, multiple processes or threads may need to access
shared resources.
○ Ensuring mutual exclusion (only one process at a time) in the critical
section is essential.
○ We want to avoid deadlock and ensure progress.
2. Dekker’s Solution:
○ Dekker’s algorithm was one of the first provably-correct solutions to the
critical section problem.
○ It allows two threads to share a single-use resource without conflict,
using only shared memory for communication.
○ Unlike naive turn-taking algorithms, Dekker’s algorithm avoids strict
alternation.
○ It was one of the earliest mutual exclusion algorithms invented.
3. Algorithm (Final Version):
○ Dekker’s algorithm requires an array of Boolean values (flag) and an
integer variable (turn).
repeat
flag[i] := true;
while flag[j] do
if turn = j then
begin
flag[i] := false;
while turn = j do no-op;
flag[i] := true;
end;
critical section
turn := j;
flag[i] := false;
until false;
Peterson’s Solution
do {
flag[i] = true;
turn = j;
while (flag[j] && turn = = j);
critical section
flag[i] = false;
remainder section
} while (true);
Dining-Philosophers Problem
signal (chopstick[i] );
signal (chopstick[ (i + 1) % 5] );
}
Sleeping Barber problem
The analogy is based upon a hypothetical barber shop with one barber. There is
a barber shop which has one barber, one barber chair, and n chairs for waiting
for customers if there are any to sit on the chair.
Semaphore Customers = 0;
Semaphore Barber = 0;
Mutex Seats = 1;
int FreeSeats = N;
Barber {
while(true) {
down(Customers);
down(Seats);
FreeSeats++;
up(Barber);
up(Seats);
/* barber is cutting hair.*/
}
}
Customer {
while(true) {
down(Seats);
if(FreeSeats > 0) {
FreeSeats--;
up(Customers);
up(Seats);
down(Barber);
// customer is having hair cut
} else {
up(Seats);
// customer leaves
}
}
}
Each IPC method has its advantages and trade-offs in terms of performance,
complexity, and suitability for different use cases. The choice of IPC mechanism
depends on factors such as the nature of the communication, performance
requirements, security considerations, and the architecture of the system.
Process creation:
Process creation is managed by the Linux kernel using system calls and utilities
provided by the operating system. Here's a basic overview of how process creation
works in Linux