Banker’s Algorithm in Operating System

banker’s algorithm

Banker’s algorithm is one of the significant parts of the operating system as it is one of the contrivances to tackle the deadlock and indeed it is deemed as the deadlock avoidance algorithm or deadlock detection. Edsger Dijkstra developed the banker’s algorithm.

It effectively analyzes all possible tests and allocates the resources to the processing in such a manner so that deadlock can be avoided. It is named so as this algorithm used in the banking system to determine whether the loan is can be sanctioned or not. 

Real-world example:

Let’s suppose there are “n” banks and the total sum of money in the bank as “T”. Now if an account holder applies for the loan, then firstly, the bank will deduct from the total cash “T” and then ascertain the cash difference which must be greater than “T” to guarantee the loan. It ensues in this way so that if other account holders come to withdraw their money and bank operate all these transaction activities smoothly without any restriction. 

Likewise, it happens in the operating system, whenever a process occurs or created in the computer system, the process should provide all the requisite information to the operating system so that os can decide accordingly which process can execute or wait in order to avoid the deadlock. It is also deemed as the amalgamation of the safety algorithm and resource request algorithm which both operate their functionality under the banker’s algorithm. 

Hence, in a way, this algorithm is used to do safely allocation of resources to the processes and additionally, it also helps in determining the maximum amount present for resources. 

Three vital things while working with Banker’s algorithm:

  1.  To what extent each process can request each resource in the system. It is referred to as [MAX] request.
  2. To what extent each process is currently holding a particular resource in a system. It is denoted as [ALLOCATED] resource.
  3. It depicts the number of each resource available in the system. It is denoted by [AVAILABLE] resource.

Data structures that are required to implement Banker’s algorithm:

  1.  Available: It is an array of lengths m. It represents the number of available resources of each type. when Available[j] = k, then there are k instances of resource type R(j) are available in the system.
  2. Max: It is an n x m matrix that represents the maximum number of instances of each resource that a process can request. If Max[i][j] = k, then the process P(i) can request at most k instances of resource type R(j). hence, it depicts each process P[i] has the ability to store maximum resources R[j] in a system.
  3. Allocation: It is an n x m matrix that represents the number of resources of each type currently allocated to each process. If Allocation[i][j] = k, then process P(i) is currently allocated k instances of resource type R(j) in the system. 
  4. Need: It is an n x m matrix that indicates the number of remaining resource needs of each process. If Need[i][j] = k, then process P(i) may need k more instances of resource type R(j) to complete its task.

Need[i][j] = Max[i][j] – Allocation[i][j].

 

  1. Finish: it is considered as the vector of the order m. It comprises the boolean value either true or false which indicates that whether the process has been allocated to the desired resource and also ensures that all the resources must be released after finishing tasks associated with the processes. 

Also Read: About Sliding Window Protocol & Its Types

Banker’s algorithm has both advantages and disadvantages:

Advantages of Banker’s algorithm:

  1.  It has adequate resources to meet the requirements of each resource. 
  2. This algorithm significantly avoids the deadlock.
  3. It assists the operating system in holding and managing process requests for each type of resource in the system.
  4. It includes the prime feature of max resource allocation which claims to hold to a maximum number of resources for each process.

 

Disadvantages of Banker’s algorithm:

  1. While processing, it doesn’t allow the process to exchange its maximum need.
  2. It requires a fixed number of processes and doesn’t allow further processes in between the execution of the process. 
  3. The number of resource requests accords for a finite period of time.
  4. Its a prerequisite condition that all processes must state their maximum requirement of resources at the starting of the system beforehand. 

Hence, Banker’s algorithm is assisting in tackling the disastrous issue of operating system i.e. deadlock. 

Add a Comment

You have to agree to the comment policy.

  +  12  =  19