Open In App

Distributed System – Banker’s Algorithm

Last Updated : 11 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Distributed systems have a banker’s algorithm which serves as a deadlock avoidance algorithm. Bankers algorithm depicts the resource allocation strategy which can help in determining the availability of resources in the present or future and how these availability of resources will lead a Bankers’ system to go into deadlock. Different data structures can be used to implement the banker’s algorithm.

Banking Algorithm Terminologies

1. Available:

  • This is used to define resource availability.
  • It is depicted by Available[j] notation.

2. Max:

  • This is used to depict the maximum resources a matrix can store.

3. Allocation:

  • A matrix depicting the resources allocated to complete the assigned work.

4. Need:

  • A matrix depicting the resources needed to complete the assigned work.
  • Matrix is depicted with Need[i][j]

5. Finish:

  • This is used to define a boolean value to determine if process has the required resources and if resources get released after task finished.

Algorithms Used in Banking Algorithms

To avoid deadlock in a system, Banker’s Algorithm includes the below two algorithms:

  • Resource Request Algorithm
  • Safety Algorithm

Safety Algorithm

The safety algorithm as the name suggests is used to determine and calculate the safety of the system. It checks on the state and sequence of the system to analyze system safety.

To determine the safety of the system it is important to understand: Work, Finish[i], and Need[i] w.r.t the available resources.

Here, Finish[i], and Need[i] include arrays of length n.

Step 1: Set Work as Available.

Work = available  - (1)
Finish[i] = false - (2)

Step 2: Check the availability of resources and continue the loop till Finish[i] is valued as false.

Need[i] <= Work - (3)
Finish[i] == false - (4)
Work = Work +Allocation(i) - (5)

Step 3: When Finish[i] is valued as true we can consider the system to be safe.

Finish[i] == true  - (6)

Resource Request Algorithm

The resource request algorithm as the name suggests is used to determine and calculate the system behavior when process makes request to resources.

To determine the resource request of the system it is important to understand: Allocation[i], Resource[i], Process[i] w.r.t the resources.

Let’s create a resource request array R[i] for each process P[i]. If the Resource Requesti [j] is equal to ‘K’, which means the process P[i] requires ‘k’ instances of Resources type R[j] in the system.

Step 1: Continue and go to step 2 if the condition is met else wait till the need meets the request.

Request(i) <= Need - (1)

Step 2: Continue and go to step 3 if the condition is met else wait till the resources become available.

Request(i) <= Available  - (2)

Step 3: Here, the requested resource is made available to the system process

Available = Available - Request - (3)
Allocation(i) = Allocation(i) + Request (i) - (4)
Need (i) = Need(i) - Request(i) - (5)

These two algorithms as discussed in the blog together constituted Banker’s algorithm.

Conclusion

  • Banker’s algorithm plays a very important part role in ensuring customer safety.
  • It ensures resource requirements are fulfilled keeping in mind all the necessary deadlock conditions.
  • Multi-process environments using a banker’s algorithm grant safety, and security and ensure adequate resources to process are made available.

FAQ on Banker’s Algorithm in a Distributed System

Q.1: Name the two algorithms that are important in banking algorithm

Answer:

The two algorithsms are as below:

1. Resource Request Algorithm

2. Safety Algorithm

Q.2: Are banking algorithms safe?

Answer:

Yes, banking algorithm is very much safe and the algorithms takes care of respecting privacy and security.

Q.3: Comment on how a banking algorithms impact customers.

Answer:

Banking algorithms enhance customer experience while ensuring safety and security.

Q.4: State the benefits of the banking algorithm.

Answer:

Benefits of banking algorithm include fraud detection, ensuring security and safety.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads