About this simulator
Deadlock happens when processes each hold resources and wait forever for resources held by others. The Banker's algorithm decides whether the system is in a safe state, and a detection algorithm finds processes that are already deadlocked. Enter your own Allocation, Max (or Request) and Available vectors and follow the search for a safe sequence while a resource-allocation graph updates.
How it works
- (avoidance) or the outstanding Request (detection).
- Start with . Find a process whose ; let it finish and add its Allocation back to Work.
- If every process can finish the state is safe (the order is a safe sequence). If none can proceed, the remaining processes are deadlocked.
Formulas used
- can run if
- when finishes
Worked example
The classic system has 5 processes and 3 resource types with Available (3, 3, 2). Starting with Work = (3, 3, 2) the algorithm finds P1 can finish (Need (1, 2, 2) ≤ Work), then P3, P4, P0 and P2. The safe sequence is P1 → P3 → P4 → P0 → P2. A request that leaves no such order is refused as unsafe.
Enter these numbers in the simulator above to see every step.
When to use it
- Solving Banker's algorithm homework with Need = Max − Allocation.
- Checking whether granting a resource request keeps the system safe.
- Spotting a circular wait in a resource-allocation graph.
Frequently asked questions
What is a safe state?
A state is safe if there is some order in which every process can obtain its remaining resources and finish. That order is called a safe sequence.
How do you calculate the Need matrix?
for every process and resource type.
Is an unsafe state always a deadlock?
No. An unsafe state only means deadlock is possible; the Banker's algorithm avoids it by refusing requests that would lead to one.
What are the four conditions for deadlock?
Mutual exclusion, hold and wait, no preemption and circular wait must all hold at the same time.