Banker's Algorithm in Operating System (OS) - Javatpoint
Banker's Algorithm in Operating System (OS) - Javatpoint
When the resource allocation state is safe, its resources are allocated to the process P(i). And if the
new state is unsafe, the Process P (i) has to wait for each type of Request R(i) and restore the old
resource-allocation state.
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
https://www.javatpoint.com/bankers-algorithm-in-operating-system 6/13
Answer the following questions using the banker's algorithm:
6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint
3. What will happen if the resource request (1, 0, 0) for process P1 can the system accept this
request immediately?
Process Need
A B C
P1 7 4 3
P2 1 2 2
P3 6 0 0
P4 0 1 1
P5 4 3 1
https://www.javatpoint.com/bankers-algorithm-in-operating-system 7/13
Available Resources of A, B and C are 3, 3, and 2.
6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint
Now we check if each type of resource request is available for each process.
https://www.javatpoint.com/bankers-algorithm-in-operating-system 8/13
Step 3: For Process P3:
6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint
P3 Need <= Available
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
https://www.javatpoint.com/bankers-algorithm-in-operating-system 9/13
New Available Resource = Available + Allocation
6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint
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.
← Prev Next →
Feedback
https://www.javatpoint.com/bankers-algorithm-in-operating-system 10/13
tutorial
Splunk SPSS Transact-SQL
6/19/24, 11:42 PM Banker's Algorithm in Operating System (OS) - javatpoint
Swagger
Preparation
Company
Interview
Questions
Company Questions
Trending Technologies
https://www.javatpoint.com/bankers-algorithm-in-operating-system 11/13