Bankers Algorithm Deadlock Avoidance Algorithm
Bankers Algorithm Deadlock Avoidance Algorithm
The Banker's Algorithm is a resource allocation and deadlock avoidance algorithm primarily
used in operating systems to ensure safe resource allocation while avoiding deadlock conditions.
It is named after its analogy to a bank managing loan requests where the bank ensures it never
allocates loans in a way that would leave it unable to meet all future possible requests.
Key Concepts:
1. Initial Setup:
o The algorithm keeps track of how many resources are currently allocated to each
process, how many are still available, and the maximum demand each process
could have.
2. Request:
o When a process requests resources, the algorithm checks if the request can be
safely granted.
3. Safety Check:
o The algorithm simulates the allocation of requested resources and checks if the
system will still be in a safe state. A state is safe if there is a sequence of
processes such that each process can finish execution with the currently available
resources or resources that will be released by previously finished processes.
4. Granting or Denying the Request:
o If the system is still in a safe state after granting the request, the resources are
allocated. Otherwise, the request is delayed until it can be safely granted.
Example:
Assume there are 3 resource types and 5 processes. Let’s look at a scenario:
• Available: [3, 3, 2] (These are the currently available instances of the three resources.)
• Max (maximum demand) for each process is as follows:
P0: [7, 5, 3]
P1: [3, 2, 2]
P2: [9, 0, 2]
P3: [2, 2, 2]
P4: [4, 3, 3]
P0: [0, 1, 0]
P1: [2, 0, 0]
P2: [3, 0, 2]
P3: [2, 1, 1]
P4: [0, 0, 2]
P0: [7, 4, 3]
P1: [1, 2, 2]
P2: [6, 0, 0]
P3: [0, 1, 1]
P4: [4, 3, 1]
If process P1 requests resources [1, 0, 2], the algorithm checks if granting this request keeps the
system in a safe state. If it does, the request is granted. If not, the process must wait.
Advantages:
• Deadlock Avoidance: The Banker's Algorithm ensures that the system remains in a safe
state by preemptively denying or delaying resource requests that might lead to deadlock.
Disadvantages:
Conclusion: