Banker's Algorithm Visualization

A deadlock avoidance algorithm for resource allocation

📚 Understanding Banker's Algorithm

Banker's Algorithm is a deadlock avoidance algorithm that tests for safety by simulating the allocation of predetermined maximum possible amounts of all resources.

Key Matrices

  • Allocation: Resources currently allocated to each process
  • Max: Maximum resources a process might need
  • Need: Additional resources a process might request (Max - Allocation)
  • Available: Resources available in the system

Algorithm Steps

  1. Calculate Need matrix (Max - Allocation)
  2. Find a process whose needs can be satisfied with available resources
  3. Allocate resources to that process
  4. Add the allocated resources back to available when process completes
  5. Repeat until all processes are allocated or no safe sequence exists

📊 Example Scenario

Consider 3 processes (P0, P1, P2) and 3 resource types (A, B, C):

Process Allocation (A,B,C) Max (A,B,C) Need (A,B,C)
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]
Total Resources: [10, 5, 7]
Available Resources: [5, 4, 5]
Safe Sequence: P1 → P0 → P2

🔧 Try It Yourself