Chapter 7 · Simulation

Banker’s Algorithm

← Chapter 7
Speed 1/s
Scenario
Procs 5
Resources 3

Step 0/0 ✓ Done 0/0 Status –

Banker’s Algorithm

The banker’s algorithm avoids deadlock: before granting a request, the system checks that the resulting state is still safe, that is, that some order exists in which every process can obtain its maximum demand and finish. The matrices show Allocation, Max (maximum demand) and Need = Max − Allocation (remaining need) for every process; the Available vector (free resources) and the Work vector are at the top, and the safe sequence is at the bottom.

Usage

  • Safety check runs the safety algorithm step by step. The Allocation, Max and Available cells are editable (integers from 0 to 99).
  • Request: enter a process and a request vector and press Check ▶ to run the resource-request algorithm; a granted request is applied to the state.
  • A scenario loads a ready-made example; the Procs and Resources counts (1–10 each) change the size of the matrices.
  • Possible requests shows the outcome of a one-unit request for every process and resource; clicking a cell animates that request.
  • ▶ plays; the step buttons move one step back or forward, or jump to the start or end.

Terms

Need
Max − Allocation
Work
Starts as Available; a finished process returns its Allocation.
Safe
There is an order in which every process can finish.
Unsafe
No such order exists; deadlock is possible but not certain.
Scan
P0, P1, … in order; passes repeat until no progress is possible.
Request
If not ≤ Need, error; if not ≤ Available, wait. Pretend to allocate; keep it only if the state is safe.

Legend

darker = larger value ✓ fits ✗ too large changed finished

Keys

←→ stepSpace playHomeEndEsc close