โ CS Visual Lab ยท Operating Systems
๐ฆ Deadlock avoidance: Banker's algorithm
๐ก The ideaBefore giving resources, the OS checks that every process can still finish in some order (a safe sequence). Need = Max โ Allocation. A process can run if its Need fits in Work; when it finishes, its allocation returns to Work.
๐ In real lifeA bank lends money only if it can still satisfy every customer's maximum loan in some order, so the bank never runs dry.
๐ฌ Watch it work
Step 1 of 7
| Process | Allocation | Max | Need = Max โ Alloc |
|---|---|---|---|
| P0 | 0 1 0 | 7 5 3 | 7 4 3 |
| P1 | 2 0 0 | 3 2 2 | 1 2 2 |
| P2 | 3 0 2 | 9 0 2 | 6 0 0 |
| P3 | 2 1 1 | 2 2 2 | 0 1 1 |
| P4 | 0 0 2 | 4 3 3 | 4 3 1 |
Check P0: Need [7 4 3] > Work [3 3 2] โ it must wait.