RTUComputer ScienceYr 2024 · Sem 52024

Q3Operating Systems (Departmental Elective)

Question

4 marks

Explain the concept of Deadlock Detection and Recovery.

Answer

A detailed exploration of Deadlock Detection and Recovery, explaining how the OS utilizes Wait-For graphs and Resource Allocation matrices to identify freezes, and aggressive process termination to recover the system.

Unlike Deadlock Prevention (which mathematically restricts resource requests) or Deadlock Avoidance (which simulates every request via the Banker's Algorithm), Deadlock Detection takes a highly aggressive, optimistic approach. The OS Kernel blindly grants any resource requested by any process immediately. However, it periodically executes a massive system-wide mathematical scan to determine if a catastrophic deadlock has silently occurred.

Phase 1: Deadlock Detection

  • Single Instance Resources (Wait-For Graph): If every hardware resource has only 1 instance (e.g., 1 physical printer), the OS mathematically collapses the Resource Allocation Graph into a "Wait-For Graph." It aggressively runs a Depth-First Search cycle-detection algorithm. If a mathematical cycle exists (e.g., A waits for B, B waits for C, C waits for A), deadlock is absolutely confirmed.
  • Multiple Instance Resources (Matrix Algorithm): If resources have multiple instances (e.g., 5 identical RAM blocks), cycles do not guarantee deadlock. The OS must run an mathematical matrix algorithm (highly similar to the Banker's algorithm safety check) using Allocation and Request matrices to definitively prove if any processes can finish.

Phase 2: Deadlock Recovery

Once the algorithm screams that a deadlock exists, the OS must violently shatter the cycle to save the system.

  • Process Termination: The absolute most brutal method. The OS can choose to instantly annihilate EVERY single process involved in the deadlock, causing massive data loss. Alternatively, it can aggressively assassinate processes one-by-one, recalculating the detection algorithm after each kill until the deadlock shatters.
  • Resource Preemption: A more surgical strike. The OS violently rips the locked resource out of the hands of an offending process. The victim process must be mathematically "Rolled Back" to a safe checkpoint state before it acquired the resource, which requires massive architectural overhead to maintain process history.
Back to Paper