Jump to content

6.5.2 Deadlock Prevention, Avoidance, Detection, Recovery

From Computer Science Knowledge Base

6.5.2 Deadlock Prevention, Avoidance, Detection, Recovery

(Difficulty Note: The names of these strategies are the key, the how is too complex.)

The OS has strategies to try and deal with deadlocks. It's like how a city manages traffic to prevent gridlock:

  • Deadlock Prevention: This means designing the system so that one of the four conditions for deadlock can never happen. For example, by making sure processes always ask for all the resources they need at once, or by allowing resources to be taken away if needed. (Like making the bridge wider so two cars can always pass, or only letting cars onto the bridge if the other side is clear).
  • Deadlock Avoidance: The OS checks each time a resource is requested to make sure that granting the request won't lead to a deadlock later. It's like a traffic controller checking the whole route before letting cars onto the bridge.
  • Deadlock Detection: If the OS doesn't prevent or avoid deadlocks, it can try to detect when one has happened. It regularly checks if any processes are stuck in a circular waiting pattern. (Like a traffic camera noticing cars are stuck.)
  • Deadlock Recovery: Once a deadlock is detected, the OS needs a way to break it. This usually involves "sacrificing" one or more processes (stopping them or forcing them to give up resources) to allow the others to continue. (Like a tow truck removing one of the stuck cars.)

These strategies help the OS keep your computer from freezing up when many programs are trying to share limited resources.

Bibliography: