The Banker
The Banker
BANKER’S ALGORITHM
1.1 Introduction
It is a resource allocation & deadlock avoidance algorithm developed by Edsger Dijkstra that
tests for safety by simulating the allocation of pre-determined maximum possible amounts of all
resources, and then makes a "safe-state" check to test for possible deadlock conditions for all
other pending activities, before deciding whether allocation should be allowed to continue.
The Banker's algorithm is run by the operating system whenever a process requests resources.
The algorithm avoids deadlock by denying or postponing the request if it determines that
accepting the request could put the system in an unsafe state (one where deadlock could occur).
When a new process enters a system, it must declare the maximum number of instances of each
resource type that may not exceed the total number of resources in the system. Also, when a
process gets all its requested resources it must return them in a finite amount of time.
The Banker's Algorithm derives its name from the fact that this algorithm could be used in a
banking system to ensure that the bank does not run out of resources, because the bank would
never allocate its money in such a way that it can no longer satisfy the needs of all its customers.
By using the Banker's algorithm, the bank ensures that when customers request money the bank
never leaves a safe state. If the customer's request does not cause the bank to leave a safe state,
the cash will be allocated, otherwise the customer must wait until some other customer deposits
enough.
request ≤ max, else set error condition as process has crossed maximum claim made
by it.
request ≤ available, else process waits until resources are available.
A state is considered safe if it is possible for all processes to finish executing (terminate). Since
the system cannot know when a process will terminate, or how many resources it will have
requested by then, the system assumes that all processes will eventually attempt to acquire their
stated maximum resources and terminate soon afterward. This is a reasonable assumption in
most cases since the system is not particularly concerned with how long each process runs (at
least not from a deadlock avoidance perspective). Also, if a process terminates without acquiring
its maximum resources, it only makes it easier on the system.
Given that assumption, the algorithm determines if a state is safe by trying to find a hypothetical
set of requests by the processes that would allow each to acquire its maximum resources and then
terminate (returning its resources to the system). Any state where no such set exists is an unsafe
state.
1.5 Requests
When the system receives a request for resources, it runs the Banker's algorithm to determine if it
is safe to grant the request. The algorithm is fairly straight forward once the distinction between
safe and unsafe states is understood.
Whether the system denies or postpones an impossible or unsafe request is a decision specific to
the operating system.
1.6 Limitations
Like other algorithms, the Banker's algorithm has some limitations when implemented.
Specifically, it needs to know how much of each resource a process could possibly request. In
most systems, this information is unavailable, making it impossible to implement the Banker's
algorithm. Also, it is unrealistic to assume that the number of processes is static since in most
systems the number of processes varies dynamically. Moreover, the requirement that a process
will eventually release all its resources (when the process terminates) is sufficient for the
correctness of the algorithm, however it is not sufficient for a practical system. Waiting for hours
(or even days) for resources to be released is usually not acceptable.