Handling Deadlocks

We can deal with the deadlock problem in one of three ways:

  1. We can use rules to prevent or avoid deadlocks, ensuring that the operating system will never enter a deadlocked state.
  2. We can allow the OS to enter a deadlocked state, detect it, and then recover from it.
  3. We can ignore the problem altogether and pretend that deadlocks never occur in the system. Surprisingly, this is the approach Windows and Linux systems take, as most deadlocks occur rarely, and it is better to let them happen and restart the computer instead of letting the operating system spend time on constantly checking for the existence of deadlocks and recovering from them.

To prevent deadlocks, the OS could prevent one of the four necessary conditions that make a deadlock occur. To avoid deadlocks, the OS needs to know more details about the running processes and the resources that they will request to use. Deadlock detection is fairly straightforward, but deadlock recovery requires either aborting processes or preempting resources, neither of which is usually desired.