0% found this document useful (0 votes)
32 views

Bankers Algorithm Deadlock Avoidance Algorithm

Uploaded by

Web Engineer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Bankers Algorithm Deadlock Avoidance Algorithm

Uploaded by

Web Engineer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Banker's 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. Processes: A set of processes competing for resources.


2. Resources: A fixed number of resource types, each with a finite number of instances.
3. Max Resources: The maximum demand each process could have.
4. Allocated Resources: Resources currently allocated to each process.
5. Available Resources: Resources that are currently available (not allocated).
6. Need: How many more resources a process will need to complete, which is calculated as
Need = Max - Allocated.

Steps of the Algorithm:

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]

• Allocated (currently allocated resources):

P0: [0, 1, 0]
P1: [2, 0, 0]
P2: [3, 0, 2]
P3: [2, 1, 1]
P4: [0, 0, 2]

• The Need matrix (Max - Allocated) will be:

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:

• Complexity: It involves multiple checks and matrices, making it computationally


expensive, especially in large systems.
• Static Resource Allocation: The maximum needs of each process must be predefined,
which is not always possible in dynamic systems.

Conclusion:

The Banker's Algorithm is a theoretical approach to managing resources efficiently in operating


systems, ensuring safe resource allocation by avoiding deadlocks. However, due to its
complexity and the need for predefined maximum resource demands, it is more suitable for
systems with predictable resource usage.

You might also like