Q1 What is a critical section problem ? What is a safe state ?
Critical Section Problem
- A critical section is a section of code, sharing or interacts with other processes in which only one process (among processes) at a time can be executing.
- Critical section problem involved in design an algorithm which allows at most one process into the critical section at a time, without deadlock.
Safe State
- A set of resource allocations such that the system can allocate resources to each process (up to its maximum requested resources) and in some order (completion sequence), and still avoid a deadlock.
Q2 Define deadlock and the four necessary conditions needed before deadlock can occur ?
A situation where every process is waiting for an event which can be triggered only by another process.
The four necessary conditions for deadlock to occur :
1 Mutual exclusion: At least one resource must be held in a non-sharable mode.
2 Hold and wait: A process holding at least one resource is waiting for more resources held by other processes.
3 No preemption: Resource cannot be preempted.
4 There must be a circular waiting condition for processes.
Question 3
Consider the following snapshot of a system. There are no current outstanding queued unsatisfied requests.
Maximum resources
r1 r2 r3 r4
6 7 12 12
current allocation maximum demand
process r1 r2 r3 r4 r1 r2 r3 r4
p1 0 0 1 2 0 0 1 2
p2 2 0 0 0 2 7 5 0
p3 0 0 3 4 6 6 5 6
p4 2 3 5 4 4 3 5 6
p5 0 3 3 2 0 6 5 2
Is this system current in a safe or unsafe state ? Why ?
needs
r1 r2 r3 r4
0 0 0 0
0 7 5 0
6 6 2 2
2 0 0 2
0 3 2 0
Running the Banker's Algorithm, we see processes can finished in the order p1, p4, p5, p2, p3. The system is in a safe state since there is a completion path.