Deadlock Recovery

When the deadlock detection program detects the existence of a deadlock, it should try to resolve it and let the system recover from the deadlock state. Common methods for resolving deadlocks include:

Method Description Advantages Disadvantages
Immediately terminate all processes Terminate the execution of all processes and restart the operating system Simple Large losses, all previous work is invalid
Cancel all deadlocked processes Cancel all processes involved in the deadlock and continue to run after the deadlock is resolved Can completely destroy the deadlock's circular waiting condition High cost, may cause some important processes to be terminated, the work done by the process will be lost, and the recovery process is troublesome.
Cancel deadlocked processes one by one Cancel processes involved in deadlock one by one, and reclaim their resources until the deadlock is resolved Flexible, you can choose the revocation order according to the process characteristics Need to determine which processes to revoke first, which may be complicated
Grab resources Grab resources from processes involved in deadlock and reallocate them to other processes Can resolve deadlock without terminating the process May cause instability in other processes, so be careful

Selection of conditions for revoking deadlocked processes one by one

When revoking deadlocked processes one by one, you can select processes that meet the following conditions to be revoked first:

  • The one that consumes the least CPU time

  • The one that generates the least output

  • The one with the longest estimated remaining execution time
  • The one that occupies the least number of resources
  • The one with the lowest priority

This method can resolve deadlocks with minimal impact by flexibly selecting the processes to be revoked.