

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: Operating Systems; Subject: Computer Science; University: University of Massachusetts - Amherst; Term: Fall 2008;
Typology: Exams
1 / 2
This page cannot be seen from the preview
Don't miss anything!


CMPSCI 377 Operating Systems Fall 2008
Lecturer: Prashant Shenoy Scribe: Shashi Singh
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 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 prevents 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).
For the Banker’s algorithm to work, it needs to know three things:
Some of the resources that are tracked in real systems are memory, semaphores and interface access.
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 (one-by-one) its maximum resources and then terminate (returning its resources to the system). Any state where no such set exists is an unsafe state. In a safe state, at least one process should be able to acquire its maximum possible set of resources, and proceed to termination.
13-2 Lecture 13: October 16
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.
Note: Look at lecture slide for the pseudocode and examples.
Like most algorithms, the Banker’s algorithm involves some trade-offs. Specifically, it needs to know how much of each resource a process could possibly request. In most systems, this information is unavailable, making the Banker’s algorithm useless. Besides, it is unrealistic to assume that the number of processes is static. 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.