You are on page 1of 5

Banker's Algorithm Simulation

Specification There should be 3 separate pop-up GUI windows(input window, animation window and status window) on your monitor although they might be on top of each other, giving the illusion of only one window.

Animation Window

There are two major parts in the animation window. The top panel consists of four little windows, indicating how many resources of each kind are left. Here different resources are represented by different colors (A-red, B-green, C-cyan, D-blue). The bottom panel consists of five little windows, representing the five processes. Resources allocated to each process are drawn inside each window, the color representation is the same as the top panel.

Input Window

All text areas in this window are editable, you can enter any number between 0 and 9. There are two 5x4 tables in the top part of this window. The left table (MAX) represents the maximum resource required by each process (P0 - P4). The right table (Allocated) represents the resourced being allocated to each process at the time being. There are two 1x4 tables in the middle. The left one (Available) represents the total number of resources that the system has. The right one (Requested) is the initial

request that user can put in. Beneath the tables are a group of buttons represents different processes that generates the initial request, you can pick only one of them. After you choose the process and the request for that process, you may hit the "Update" button which will update the program about the parameters you have just entered. Across the bottom panel of the input window are the available operation control buttons including "Start", "Stop", "Resume", and "Quit".

Click "Start" to start the animation. Click "Stop" to pause the animation. Click "Resume" to resume the animation. Click "Quit" to close the animation window.

Status Window

The status window tells you what the program is doing, like initializing, requesting by a process, safty check result, etc.

Banker's Algorithm The Banker's Algorithm is a strategy for deadlock prevention. In an operating system, deadlock is a state in which two or more processes are "stuck" in a circular wait state. All deadlocked processes are waiting for resources held by other processes. Because most systems are non-preemptive (that is, will not take resources held by a process away from it), and employ a hold and wait method for dealing with system resources (that is, once a process gets a certain resource it will not give it up voluntarily), deadlock is a dangerous state that can cause poor system performance. One reason this algorithm is not widely used in the real world is because to use it the operating system must know the maximum amount of resources that every process is going to need at all times. Therefore, for example, a just-executed program must

declare up-front that it will be needing no more than, say, 400K of memory. The operating system would then store the limit of 400K and use it in the deadlock avoidance calculations. The Banker's Algorithm seeks to prevent deadlock by becoming involved in the granting or denying of system resources. Each time that a process needs a particularnon-sharable resource, the request must be approved by the banker. The banker is a conservative loaner. Every time that a process makes a request of for a resource to be ``loaned'' the banker takes a careful look at the bank books and attempts to determine whether or not a deadlock state could possibly arise in the future if the loan request is approved. This determination is made by ``pretending'' to grant the request and then looking at the resulting post-granted request system state. After granting a resource request there will be an amount of that resource left free in the system, f. Further, there may be other processes in system. We demanded that each of these other processes state the maximum amount of all system resources they needed to terminate up-front so, therefore, we know how much of each resource every process is allocatedand has claim to. If the banker has enough free resource to guarantee that even one process can terminate, it can then take the resource held by that process and add it to the free pool. At this point the banker can look at the (hopefully) now larger free pool and attempt to guarantee that another process will terminate by checking whether itsrequest can be met. If the banker can guarantee that all jobs in system will terminate, it approves the loan in question. If, on the other hand, at any point in the reduction the banker cannot guarantee any processes will terminate because there is not enough free resource to meet the smallest request, a state of deadlock can ensue. This is called an unsafe state. In this case the loan request in question is denied and the requesting process is usuallyblocked. Source: there are altogether three files that build up banker's algorithm. "banker.java" defines the algorithm as a whole (much like a driver for the algorithm), while safty check and some other funtionalities are defined by "managementData.java". Functions related to each single process are defined in "simpleProcess.java".

Technical Support:

GUI input window animation window status window Class heirarchy driver banker's algorithm managementData simpleProcess GUI listener GUI data Go to applet
Z. James Chen Algorithm Animation project Multimedia (CS 8302) UT Dallas Summer, 2000

You might also like