Banker's Algorithm
Introduction:
Bankers algorithm is an algorithm which is used for deadlock avoidance
and resource allocation. It was established by Edsger Dijkstra. The
reason behind the name 'banker's algorithm' is that it
is mostly used in banking systems. Banker's algorithm helps to identify
whether a loan should be provided or not. The
'S-State' examines all possible tests or activities
before deciding whether the allocation should be allowed to each
process. It also helps the operating system to successfully share the
resources between all the processes. When a new process is created in a
computer system, the process must provide all types of information to
the operating system like 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 or
deadlock detection in the operating system .
Characteristics of Banker's Algorithms:
- If a process demands the resources, then it has to wait.
-
Banker's algorithm consists of advanced features for maximum resource
allocation.
-
In the banker's algorithm, various resources are maintained that
fulfill the needs of at least one client.
- In the system, we have limited resources.
-
In the banker's algorithm, if the process gets all the needed
resources, then it is must to return the resources in a restricted
period.
Advantages:
-
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.
-
It helps the operating system manage and control process requests for
each type of resource in the computer system.
-
The algorithm has a Max resource attribute that represents indicates
each process can hold the maximum number of resources in a system.
Disadvantages:
-
It requires a fixed number of processes, and no additional processes
can be started in the system while executing the process.
-
The algorithm does no longer allows the processes 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.
Data structures terms applied in the banker's algorithm as follows:
Suppose n is the number of processes, and m is the number of each type
of resource used in a computer system.
-
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 the system.
-
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].