Program 4
Program 4
DEADLOCK AVOIDANCE
❖ Simplest and useful model
❖ Process is required to declare max no. of resources of each type
needed.
❖ Resource allocation state is defined by:
1. Available resources
2. Allocated resources
3. Max. demand of process
SAFE STATE
❖ When a process requires an available resource, the system must
decide if immediate allocation leaves the system in safe state.
❖
❖
BANKER’S ALGORITHM
❖ Multiple Instances
❖ When a process requests a resource, it may have to wait.
❖ When a process gets all the needed resources, it must return them
in a Finite amount of time.
❖ Each process must a priority claim maximum use.
Max = n x m Matrix.
If Max[i, j] = k, then process Pi may request at most
k instances of resources type Rj.
Allocation = n x m Matrix.
If Allocation[i, j] = k, then Pi is currently
currently allocated k instances of Rj.
Need = n x m Matrix.
If need[i, j] = k, then Pi may need k more
Instances of Rj to complete its tasks.
R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3
P1 0 1 0 7 5 3 3 3 2 7 4 3
P2 2 0 0 3 2 2 1 1 2
P3 3 0 2 9 0 2 6 0 0
P4 2 1 2 2 2 2 0 1 1
P5 0 0 2 4 3 3 4 3 1
Step 1
To find need
Step 3
Now checking the condition again for P1 & P3
Therefore,
OUTPUT