Banker's algorithm
Banker's algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for safety by simulating the allocation of predetermined maximum possible amounts of all resources, and then makes an "s-state" check to test for possible deadlock conditions for all other pending activities, before deciding whether allocation should be allowed to continue.[src] The algorithm was developed in the design process for the THE operating system and originally described (in Dutch) in EWD108.[src] When a new process enters a system, it must declare the maximum number of instances of each resource type that it may ever claim; clearly, that number may not exceed the total number of resources in the system.[src] Also, when a process gets all its requested resources it must return them in a finite amount of time.[src]
Banker's algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for safety by simulating the allocation of predetermined maximum possible amounts of all resources, and then makes an "s-state" check to test for possible deadlock conditions for all other pending activities, before deciding whether allocation should be allowed to continue.[src] The algorithm was developed in the design process for the THE operating system and originally described (in Dutch) in EWD108.[src] When a new process enters a system, it must declare the maximum number of instances of each resource type that it may ever claim; clearly, that number may not exceed the total number of resources in the system.[src] Also, when a process gets all its requested resources it must return them in a finite amount of time.[src] Available: A vector of length m indicates the number of available resources of each type.[src] If Available[j] = k, there are k instances of resource type R j available.[src] Max: An × matrix defines the maximum demand of each process.[src] If Max[i,j] = k, then P i may request at most k instances of resource type R j .[src] Allocation: An × matrix defines the number of resources of each type currently allocated to each process.[src] If Allocation[i,j] = k, then process P i is currently allocated k instances of resource type R j .[src] Need: An × matrix indicates the remaining resource need of each process.[src] If Need[i,j] = k, then P i may need k more instances of resource type R j to complete the task.[src] Note: Need[i,j] = Max[i,j] - Allocation[i,j].[src] n=m-a.[src] Need = maximum resources - currently allocated resources [available resource: − = ] The system now still has 1 A, no B, 1 C and 1 D resource available P1 terminates, returning 3 A, 3 B, 2 C and 2 D resources to the system [available resource: + = ] The system now has 4 A, 3 B, 3 C and 3 D resources available P2 acquires 2 B and 1 D extra resources, then terminates, returning all its resources [available resource: − + = ] The system now has 5 A, 3 B, 6 C and 6 D resources P3 acquires 1 B and 4 C resources and terminates.[src] [available resource: − + = ] The system now has all resources: 6 A, 5 B, 7 C and 6 D Because all processes were able to terminate, this state is safe For an example of an unsafe state, consider what would happen if process 2 was holding 1 unit of resource B at the beginning.[src] import numpy as np n_processes = int(input("Number of processes?[src] ")) n_resources = int(input("Number of resources?[src] ")) available_resources = [int(x) for x in input("Claim vector?[src] ").split(" ")] currently_allocated = np.array([ [int(x) for x in input(f"Currently allocated for process {i + 1}?[src] ").split(" ")] for i in range(n_processes) ]) max_demand = np.array([ [int(x) for x in input(f"Maximum demand from process {i + 1}?[src] ").split(" ")] for i in range(n_processes) ]) total_available = available_resources - np.sum(currently_allocated, axis=0) running = np.ones(n_processes) # An array with n_processes 1's to indicate if process is yet to run while np.count_nonzero(running) > 0: at_least_one_allocated = False for p in range(n_processes): if running[p]: if all(i >= 0 for i in total_available - (max_demand[p] - currently_allocated[p])): at_least_one_allocated = True print(f"{p} is running") running[p] = 0 total_available += currently_allocated[p] if not at_least_one_allocated: print("Unsafe") break # exit else: print("Safe") ==References==[src]
26 sentences · 26 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Banker's algorithm." encyclopegia.org, 2025, https://encyclopegia.org/wiki/banker-s-algorithm. Accessed 28 November 2026.
Chicago
"Banker's algorithm." encyclopegia.org. Accessed November 28, 2026. https://encyclopegia.org/wiki/banker-s-algorithm.
APA
encyclopegia.org. (2025). Banker's algorithm. Retrieved November 28, 2026, from https://encyclopegia.org/wiki/banker-s-algorithm
Accessed November 28, 2026 · CC BY-SA 4.0 · citation page · JSON