Banker's algorithm, step by step
Safety check and request granting with practice sets.
Module 2
Session 2.6
Lesson 2 of 2
Banker's algorithm, step by step
Never enter an unsafe state: check safety before granting any request.
The idea
Like a bank that never lends out cash in a way that could leave it unable to satisfy all customers' maximum claims, the OS grants a request only if afterwards there is still an order in which every process can finish.
Practice set 1 — the textbook example
Banker's algorithmTry request 1: 1 0 2, then 4: 3 3 0.
Practice set 2 — is this state safe?
4 processes, resources A B C D. Solve by hand first.
Banker's algorithmAnswer: safe, sequence P0 → P2 → P3 → P1 (scan order).
Practice set 3 — an unsafe state
Banker's algorithmNo process can finish first → unsafe.
Quick check
Need is computed as…
What a process may still request.
A request is larger than the process's Need. The OS…
It has exceeded its declared maximum claim.
A request is ≤ Need and ≤ Available, but the resulting state is unsafe. The OS…
Avoidance never enters an unsafe state.