Complete the code to identify the condition that causes a deadlock.
if (resource_allocation == [1]) { // Deadlock detected }
The circular wait condition is one of the necessary conditions for a deadlock to occur. Detecting this condition helps identify deadlocks.
Complete the code to check if a process is part of a deadlock cycle.
if (process_waits_for(process1, [1])) { // Process is in deadlock }
Deadlock involves processes waiting for other processes to release resources, so checking if process1 waits for process2 helps detect deadlock cycles.
Fix the error in the deadlock detection function by completing the missing condition.
function detect_deadlock() {
for each process in processes {
if (process.state == [1]) {
check_cycle(process);
}
}
}Only processes in the waiting state can be part of a deadlock, so the detection function should check those.
Fill both blanks to complete the recovery step after detecting deadlock.
function recover_deadlock() {
select [1] to terminate;
release [2] held by it;
}Recovery from deadlock often involves terminating a process and releasing the resources it holds to break the deadlock cycle.
Fill all three blanks to complete the deadlock detection algorithm snippet.
for each [1] in system { if ([2] waits for [3]) { mark as deadlocked; } }
The algorithm checks each process to see if it waits for a resource held by another process, indicating deadlock.