Banker's Algorithm in Operating System
Banker's Algorithm in Operating System
Banker's Algorithm in Operating System
Example: Consider a system that contains five processes P1, P2, P3, P4, P5 and
the three resource types A, B and C. Following are the resources types: A has 10, B
has 5 and the resource type C has 7 instances.
P1 0 1 0 7 5 3 3 3 2
P2 2 0 0 3 2 2
P3 3 0 2 9 0 2
P4 2 1 1 2 2 2
P5 0 0 2 4 3 3
P1 7 4 3
P2 1 2 2
P3 6 0 0
P4 0 1 1
P5 4 3 1
Now we check if each type of resource request is available for each process.
5, 3, 2 + 2, 1, 1 => 7, 4, 3
7, 4, 3 + 0, 0, 2 => 7, 4, 5
Now, we again examine each type of resource request for processes P1 and P3.
7, 4, 5 + 0, 1, 0 => 7, 5, 5
7, 5, 5 + 3, 0, 2 => 10, 5, 7
Hence, we execute the banker's algorithm to find the safe state and the safe
sequence like P2, P4, P5, P1 and P3.
Ans. 3: For granting the Request (1, 0, 2), first we have to check that Request <=
Available, that is (1, 0, 2) <= (3, 3, 2), since the condition is true. So the process
P1 gets the request immediately.