Banker’s Algorithm in C

Here you will get program for banker’s algorithm in C.

The banker’s algorithm  which is also known as avoidance algorithm is a deadlock detection algorithm. It was developed by Edsger Dijkstra. It is designed to check the safe state whenever a resource is requested. It takes analogy of bank, where customer request to withdraw cash. Based on some data the cash is lent to the customer. The banker can’t give more cash than what the customer has requested for, and the total available cash.  As this algorithm uses bank analogy so named as banker’s algorithm

Banker’s Algorithm in C

The basic data structures used to implement this algorithm are given below.

Let n be the total number of processes and m be the total number of resource types in the system.

Available: A vector of length m. It shows number of available resources of each type. If Available[i] = k, then k instances of resource Ri are available.

Max: An n×m matrix that contain maximum demand of each process. If Max[i,j] = k, then process Pi can request maximum k instances of resource type Rj.

Allocation: An n×m matrix that contain number of resources of each type currently allocated to each process. If Allocation[i,j] = k, then Pi is currently allocated k instances of resource type Rj.

Need: An n×m matrix that shows the remaining resource need of each process. If Need[i,j] = k, then process Pi may need k more instances of resource type Rj to complete the task.

Program for Banker’s Algorithm in C

If you found anything incorrect in above program for banker’s algorithm in C then comment below.

Source: https://en.wikipedia.org/wiki/Banker%27s_algorithm

33 thoughts on “Banker’s Algorithm in C”

  1. Really great post nice work i love your work and its really helped me in my research. Thanks…………………………….

  2. Your all operating system codes are simple & easy to understand and especially your programs are all well executable and thanks for your work and keep doing it bro….

  3. This code is not true in all possible cases because once go through all process it(code) does not again check the remaining process (that are not executed). There is the possibility of their execution with new AVAILABLE DATA.
    please recheck it.

      1. i am wearing specs but i cant see anything ,anyways thankyou so much DARLING!!! with LOVE take care BYE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  4. krutika Bijjargi

    pls give comments in ur program .. it will be helpfull to understand the flow of code.. n metion out put screen for program

  5. actually it is good for only safe condition but not work for unsafe condition as in unsafe condition count value cannot be zero and while loop cannot be finished until count value is zero thus it undergoes infinite loop. please recheck it…

  6. Thank you so much to share i was searching for this program from last 2 days but got it here!

    thank you so much to share this Program

Leave a Comment

Your email address will not be published. Required fields are marked *