Banker's Algorithm in Operating System
The Banker's Algorithm is a resource allocation and deadlock avoidance algorithm. It helps the
operating system decide whether to allocate resources to a process by checking if the system will
remain in a safe state. It works like a banker who lends money only if he knows he will get it back
safely.
Key Terms:
1. Available: Resources currently free.
2. Max: Maximum resources a process may need.
3. Allocation: Resources already allocated to a process.
4. Need: Remaining resources a process still requires (Max – Allocation).
Steps of the Algorithm:
1. A process makes a request for some resources.
2. The system checks if granting the request keeps the system in a safe state.
- Safe state means there exists some sequence where all processes can finish.
3. If safe → Allocate resources.
4. If unsafe → Make the process wait.
Example:
Total resources = 10
Two processes: A and B
Process Max Need Already Allocated Still Needs
A 7 3 4
B 5 2 3
Available Resources 5
Case 1: Process A asks for 4
- If granted: Available = 5 – 4 = 1
- A now has 7 (its max), so it can finish and release 7 back.
- Available = 1 + 7 = 8
- B needs 3, and we have 8 → B can finish.
■ Safe State
Case 2: Process A asks for 7
- If granted: Available = 5 – 7 = –2 (not possible)
■ Unsafe, request denied.
Conclusion:
The Banker's Algorithm ensures resources are allocated only if it keeps the system in a safe state,
preventing deadlock. It uses a safety check before granting requests, similar to how a banker lends
money safely.