Deadlock Detection
This is the most liberal strategy. Periodically, the OS performs an algorithm that allows it to detect the circular wait condition.
The algorithm proceeds by marking processes that are not part of a deadlocked set.
Initially, all processes are unmarked. Then the following steps are performed:
- Mark each process that has a row in the Allocation matrix of all zeros. A process that has no allocated resources cannot participate in a deadlock.
- Initialize a temporary vector to equal the Available vector.
- Find an index such that process is currently unmarked and the ith row of is less than or equal to . That is, , for . If no such row is found, terminate the algorithm.
- If such a row is found, mark process i and add the corresponding row of the allocation matrix to . That is, set , for . Return to step 3.
- Mark P4, because P4 has no allocated resources.
- Set .
- The request of process P3 is less than or equal to W, so mark P3 and set
- No other unmarked process has a row in that is less than or equal to . Therefore, terminate the algorithm.
The algorithm concludes with P1 and P2 unmarked, indicating these processes are deadlocked.
Deadlock Recovery
- Abort all deadlocked processes
- Back up each deadlocked process to some previously defined checkpoint, and restart all process
- Original deadlock may occur
- Successively abort deadlocked processes until deadlock no longer exists
- Successively preempt resources until deadlock no longer exists