Banker’s Algorithm is a deadlock detection algorithm. It is named so because it is used to check whether a loan can be offered to a particular person. When a new process is created in a upcoming processes, requests for their resources, counting them, and delays. Based on these criteria, the operating system decides which process sequence should be executed or waited so that no deadlock occurs in a system. Therefore, it is also known as deadlock avoidance algorithm.
Characteristics of Banker's Algorithm:
It contains various resources that meet the requirements of each process.
Each process should provide information to the operating system for upcoming resource requests, the number of resources, and how long the resources will be held.
The algorithm has a Max resource attribute that represents indicates each process can hold the maximum number of resources in a system.
Disadvantages of banker’s algorithm:
It requires a fixed number of processes, and no additional processes can be started in the system while executing the process.
The algorithm no longer allows the process to exchange its maximum needs while processing its tasks.
Each process has to know and state their maximum resource requirement in advance for the system.
The number of resource requests can be granted in a finite time, but the time limit for allocating the resources is one year.
Working:
Available:
It is an array of length 'm' that defines each type of resource available in the
system. When Available[j] = K, means that 'K' instances of Resources type
R[j] are available in the system.
Max:
It is a [n x m] matrix that indicates each process P[i] can store the maximum
number of resources R[j] (each type) in a system.
Allocation:
It is a matrix of m x n orders that indicates the type of resources currently
allocated to each process in the system. When Allocation [i, j] = K, it means
that process P[i] is currently allocated K instances of Resources type R[j] in
Need:
It is an M x N matrix sequence representing the number of remaining
resources for each process. When the Need[i] [j] = k, then process P[i] may
require K more instances of resources type Rj to complete the assigned
work.
Need[i][j] = Max[i][j] - Allocation[i][j].
Finish:
It is the vector of the order m. It includes a Boolean value (true/false)
indicating whether the process has been allocated to the requested
Algorithm:
There are two vectors work and finish of length m and n in a safety
algorithm. Initially, work=available, finish[i]=false for all i from 0 to n-1.
Check the availability status of each type of resources [i], such as:
need[i]<=work;
finish[i]==false;
if(i doesn’t exist) go to step 4.
work=work+allocation[i]//to get new resource allocation
finish[i]=true;