Tuesday, January 21, 2014

Banker's algorithm

Banker's algorithm

Reference : http://en.wikipedia.org/wiki/Banker's_algorithm

The 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.

Prerequisites
For the Banker's algorithm to work, it needs to know three things:
  • How much of each resource each process could possibly request[CLAIMS]
  • How much of each resource each process is currently holding[ALLOCATED]
  • How much of each resource the system currently has available[AVAILABLE]
Resources may be allocated to a process only if it satisfies the following conditions:
  1. request ≤ max, else set error condition as process has crossed maximum claim made by it.
  2. request ≤ available, else process waits until resources are available.

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.
  1. Can the request be granted?
    • If not, the request is impossible and must either be denied or put on a waiting list
  2. Assume that the request is granted
  3. Is the new state safe?
    • If so grant the request
    • If not, either deny the request or put it on a waiting list
Whether the system denies or postpones an impossible or unsafe request is a decision specific to the operating system.

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.

No comments:

Post a Comment