πŸŽ“ BookMCQ
← Back to 7. Deadlocks

πŸ“ Deadlock Detection in Operating System (37 MCQs)

Identifying Deadlocks After Resource Allocation

Deadlock detection is a resource-management approach in which the operating system allows resource allocations to proceed and periodically examines the resulting process dependencies. It uses allocation records, outstanding requests, and resource availability to identify processes that cannot make progress. Unlike prevention and avoidance, detection does not guarantee that every allocation preserves a safe state before granting resources.

Why Systems May Allow Resource Conflicts Before Checking

Prevention and avoidance can restrict resource allocation or require detailed advance information about process demands. Some systems prefer more flexible allocation and accept the possibility of deadlock. Detection provides a way to identify actual deadlocked processes after allocation, allowing the operating system or application to initiate an appropriate recovery strategy.

Graph-Based and Matrix-Based Detection Procedures

For single-instance resource types, a wait-for graph can be examined for cycles. For multiple instances, a detection algorithm uses Available, Allocation, and Request information together with Work and Finish vectors. It repeatedly identifies processes whose outstanding requests can be satisfied and assumes that they release their resources upon completion.

Detecting Two Processes Waiting for Each Other

Suppose P1 holds R1 and requests R2, while P2 holds R2 and requests R1. If each resource has one instance, a wait-for graph contains P1 pointing to P2 and P2 pointing to P1. The resulting cycle identifies the two processes as deadlocked and unable to complete their pending requests.

Detection Frequency and Recovery Overhead

Detection gives systems flexibility to allocate resources without enforcing strict avoidance rules. However, frequent scans consume processing time, while infrequent detection allows deadlocks to persist longer and occupy resources. The operating system must balance detection overhead against recovery costs, workload characteristics, and the impact of blocked processes.

Misconceptions About Deadlock Detection

'Detection prevents deadlock before it occurs' is incorrect because it identifies existing deadlocks. 'Every blocked process must be part of a deadlock' is incorrect because normal resource waiting may eventually end. 'A cycle proves deadlock for every resource configuration' is incorrect because multiple resource instances require additional analysis.

Exam Focus: Identifying Deadlocked Processes from System State

Distinguish detection from prevention and avoidance and identify the information required by each approach. Trace wait-for graph cycles for single-instance resources and Work-Finish calculations for multiple instances. Questions may require you to identify unfinished processes, interpret detection results, or determine when recovery should begin.

Key Terms of Deadlock Detection

  • Detection - Identifying existing deadlock conditions.
  • Wait-for graph - Graph of process dependencies.
  • Available - Currently free resources.
  • Request - Outstanding resource requirement.
  • Work - Temporary resource availability vector.
  • Finish - Process completion indicator.
7
Easy
19
Medium
11
Hard

πŸ“ All Deadlock Detection in Operating System MCQs

Q1. When is a deadlock detection scheme typically employed?

A.When the system uses strict deadlock prevention.
B.When the system uses deadlock avoidance.
C.When the system employs neither prevention nor avoidance algorithms. βœ…
D.When the system has only one process.
πŸ’‘ Difficulty: easy | βœ… Correct: C

πŸ“– Explanation: Deadlock detection is used in environments where the system does not proactively prevent deadlocks (via prevention) or avoid them (via avoidance). It allows deadlocks to occur and then detects and recovers from them.

Q2. What are the two primary components of a deadlock detection-and-recovery scheme?

A.Prevention and Avoidance
B.Detection Algorithm and Recovery Algorithm βœ…
C.Allocation and Request
D.Safety Check and Cycle Check
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: The system must provide an algorithm to examine the state and determine if a deadlock has occurred (Detection) and an algorithm to resolve the situation once detected (Recovery).

Q3. What is the primary function of the detection algorithm?

A.To prevent deadlocks from forming.
B.To avoid unsafe states.
C.To examine the system state to determine if a deadlock has already occurred. βœ…
D.To allocate resources efficiently.
πŸ’‘ Difficulty: easy | βœ… Correct: C

πŸ“– Explanation: Unlike prevention or avoidance, which act proactively, the detection algorithm acts reactively. It inspects the current state of resource allocation and process waiting to identify if a circular wait (deadlock) currently exists.

Q4. What is the role of the recovery algorithm?

A.To detect the deadlock.
B.To break the deadlock after it has been detected. βœ…
C.To prevent the deadlock from occurring.
D.To simulate resource requests.
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Once the detection algorithm confirms a deadlock, the recovery algorithm takes steps to resolve it, such as terminating processes or preempting resources, to allow the system to continue functioning.

Q5. Does the detection-and-recovery scheme apply to systems with single-instance resources?

A.No, only multiple instances.
B.Yes, it applies to single-instance systems. βœ…
C.No, only single-instance systems.
D.It depends on the CPU architecture.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: The text explicitly states that the discussion elaborates on detection requirements for systems with only a single instance of each resource type, as well as those with several instances.

Q6. Does the detection-and-recovery scheme apply to systems with multiple-instance resources?

A.No, only single instances.
B.Yes, it applies to multiple-instance systems. βœ…
C.No, Banker's algorithm is used instead.
D.It depends on the memory size.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: The text confirms that detection-and-recovery schemes are applicable to systems with several instances of each resource type, offering an alternative to avoidance algorithms like Banker's.

Q7. What is a significant disadvantage of using a detection-and-recovery scheme?

A.It guarantees no deadlocks.
B.It requires no overhead.
C.It incurs overhead including run-time costs and potential recovery losses. βœ…
D.It is faster than prevention.
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: The text notes that this scheme requires overhead. This includes the computational cost of maintaining state information, executing the detection algorithm, and the potential negative impacts (losses) associated with recovering from a deadlock (e.g., process termination).

Q8. Which of the following is NOT part of the overhead associated with detection-and-recovery?

A.Run-time costs of maintaining information.
B.Execution cost of the detection algorithm.
C.Potential losses from recovery.
D.Cost of preventing deadlocks initially. βœ…
πŸ’‘ Difficulty: medium | βœ… Correct: D

πŸ“– Explanation: Prevention is a different strategy. The overheads listed for detection-and-recovery are maintaining info, running detection, and recovery losses. Prevention costs are irrelevant because this scheme is used when prevention is *not* employed.

Q9. In a system using detection, when can a deadlock occur?

A.Never.
B.Only during startup.
C.At any time if resources are requested in a conflicting manner. βœ…
D.Only if there are multiple instances.
πŸ’‘ Difficulty: medium | βœ… Correct: C

πŸ“– Explanation: Since neither prevention nor avoidance is used, there are no restrictions on resource requests to prevent circular waits. Therefore, a deadlock can occur whenever processes request and hold resources in a way that creates a cycle.

Q10. What distinguishes detection from avoidance?

A.Detection prevents deadlocks; avoidance finds them.
B.Detection finds existing deadlocks; avoidance prevents entering unsafe states. βœ…
C.Detection is faster; avoidance is slower.
D.Detection uses graphs; avoidance does not.
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Avoidance (like Banker's) proactively ensures the system stays in a safe state to prevent deadlocks. Detection allows the system to enter potentially unsafe states and only acts after a deadlock has actually formed.

Q11. In a Wait-For Graph, what do the nodes represent?

A.Resources
B.Processes βœ…
C.Both Processes and Resources
D.Memory Blocks
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: A Wait-For Graph is a simplified version of the Resource-Allocation Graph used for single-instance resources. It removes the resource nodes and only contains process nodes. An edge indicates one process is waiting for another.

Q12. How is a Wait-For Graph derived from a Resource-Allocation Graph?

A.By adding more resource nodes.
B.By removing process nodes.
C.By removing resource nodes and collapsing edges. βœ…
D.By reversing all edges.
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: To create a WFG from a RAG (for single instances), you remove the resource nodes. If Process P1 waits for Resource R, and Resource R is held by Process P2, you create a direct edge P1 -> P2 in the WFG. This collapses the P1->R->P2 path into P1->P2.

Q13. What does an edge from Pi to Pj in a Wait-For Graph signify?

A.Pi is holding a resource needed by Pj.
B.Pi is waiting for a resource held by Pj. βœ…
C.Pj is waiting for a resource held by Pi.
D.Pi and Pj are sharing a resource.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: In a WFG, an edge Piβ†’PjP_i \to P_j means that process PiP_i is blocked, waiting for a resource that is currently allocated to (held by) process PjP_j.

Q14. If a Wait-For Graph contains a cycle, what does it indicate?

A.The system is safe.
B.A deadlock has occurred. βœ…
C.Resources are free.
D.The system is efficient.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: For systems with single-instance resources, a cycle in the Wait-For Graph is a necessary and sufficient condition for deadlock. It means a circular chain of processes is waiting for each other.

Q15. Why might a system choose detection over prevention?

A.Prevention is too complex.
B.Prevention may reduce system throughput and concurrency by imposing strict rules. βœ…
C.Detection is always faster.
D.Detection requires no algorithms.
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Deadlock prevention often imposes restrictive conditions (e.g., no hold-and-wait) that can lead to poor resource utilization and reduced concurrency. Detection allows more freedom in resource usage, accepting the risk of occasional deadlocks which are then resolved.

Q16. What is meant by potential losses inherent in recovering from a deadlock"?"

A.Loss of electrical power.
B.Loss of data or work done by terminated/preempted processes. βœ…
C.Loss of network connectivity.
D.Loss of hardware components.
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Recovery often involves aborting processes or preempting resources. Aborting a process may mean losing the computation it has performed so far. Preempting resources may require rolling back a process to a previous state, leading to lost work.

Q17. Can a detection algorithm be used for multiple-instance systems?

A.No, never.
B.Yes, but the algorithm is different from the single-instance case. βœ…
C.Yes, using the same Wait-For Graph method.
D.No, only Banker's algorithm works.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: The text states detection applies to both single and multiple instances. However, the simple cycle detection in a WFG works for single instances. For multiple instances, a more complex algorithm (similar to the safety algorithm but checking for current deadlock rather than future safety) is required.

Q18. What information must be maintained at run-time for detection?

A.Only the number of processes.
B.The state of resource allocation (who holds what, who waits for what). βœ…
C.Only the CPU speed.
D.The history of all past allocations.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: To detect deadlocks, the system must track the current state: which resources are allocated to which processes, and which processes are waiting for which resources. This dynamic information is essential for the detection algorithm.

Q19. If a system employs deadlock avoidance, does it need a detection algorithm?

A.Yes, always.
B.No, because avoidance prevents deadlocks from occurring. βœ…
C.Yes, for backup.
D.No, because detection is impossible.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Deadlock avoidance ensures the system never enters an unsafe state where deadlock could occur. Therefore, if implemented correctly, deadlocks should never happen, making a detection algorithm unnecessary.

Q20. What is the main trade-off when choosing not to use prevention or avoidance?

A.Higher complexity for better safety.
B.Lower overhead during normal operation but risk of deadlock and recovery costs. βœ…
C.Faster processing but less memory.
D.More resources but slower CPU.
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: By skipping prevention/avoidance, the system avoids their continuous computational overhead and restrictions. However, it risks deadlocks occurring, which incurs the cost of detection and the potential damage/cost of recovery.

Q21. If P1 waits for R2, and R2 is held by P2, how does this appear in the Wait-For Graph?

A.Edge P1 -> R2
B.Edge R2 -> P2
C.Edge P1 -> P2 βœ…
D.Edge P2 -> P1
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: The WFG collapses the resource node. Since P1 waits for R2 and P2 holds R2, P1 is effectively waiting for P2. Thus, a direct edge P1 -> P2 is created in the WFG.

Q22. Which graph is more compact for single-instance systems?

A.Resource-Allocation Graph
B.Wait-For Graph βœ…
C.They are the same size.
D.Depends on the number of resources.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: The Wait-For Graph is more compact because it eliminates resource nodes. It only shows the dependencies between processes, reducing the number of nodes and simplifying cycle detection.

Q23. What happens if a deadlock is detected but no recovery algorithm is present?

A.The system automatically fixes it.
B.The involved processes remain blocked indefinitely. βœ…
C.The system reboots.
D.The resources are freed.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Detection only identifies the problem. Without a recovery mechanism, the system knows a deadlock exists but cannot resolve it. The processes involved will remain in a permanent waiting state, effectively hanging that part of the system.

Q24. Why is maintaining state information considered an overhead?

A.It requires extra hardware.
B.It consumes CPU cycles and memory to track allocations and requests continuously. βœ…
C.It slows down the disk.
D.It increases network traffic.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Every time a resource is requested or released, the system must update its internal data structures (tables, graphs). This bookkeeping consumes processing time and memory, which is overhead that wouldn't exist if no tracking was done.

Q25. Is deadlock detection proactive or reactive?

A.Proactive
B.Reactive βœ…
C.Both
D.Neither
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Detection is reactive because it identifies a deadlock *after* it has occurred. Prevention and avoidance are proactive because they try to stop deadlocks from happening in the first place.

Q26. What is the condition for deadlock in a single-instance system using a Wait-For Graph?

A.Absence of cycles
B.Presence of a cycle βœ…
C.High CPU usage
D.Low memory
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: In a single-instance resource system, the presence of a cycle in the Wait-For Graph is equivalent to a deadlock. Each process in the cycle is waiting for the next, creating an unresolvable circular wait.

Q27. Which strategy allows the highest degree of concurrency?

A.Deadlock Prevention
B.Deadlock Avoidance
C.Deadlock Detection and Recovery βœ…
D.None, they are equal.
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: Prevention imposes strict rules (limiting concurrency). Avoidance restricts requests to stay safe (limiting concurrency). Detection allows processes to request resources freely, maximizing concurrency, at the risk of occasional deadlocks.

Q28. What is the primary goal of the recovery algorithm?

A.To detect the deadlock.
B.To restore the system to a non-deadlocked state. βœ…
C.To prevent future deadlocks.
D.To optimize resource usage.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Once a deadlock is detected, the recovery algorithm's job is to break the circular wait. This restores the system to a state where processes can proceed, although it may involve sacrificing some progress (e.g., killing a process).

Q29. Can a Wait-For Graph be used for multiple-instance resources?

A.Yes, directly.
B.No, because a cycle doesn't necessarily imply deadlock in multiple-instance systems. βœ…
C.Yes, if you add weights.
D.No, because resources are not shared.
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: In multiple-instance systems, a cycle in a WFG (if one were constructed) is necessary but not sufficient for deadlock. A process might be waiting for a resource held by another, but if multiple instances exist, the resource might become available without the holder releasing it (if another instance is freed). Thus, simple WFG cycle detection is insufficient.

Q30. What is the run-time cost" mentioned in the text?"

A.The cost of buying the computer.
B.The computational overhead of executing the detection algorithm and maintaining state. βœ…
C.The cost of electricity.
D.The salary of the operator.
πŸ’‘ Difficulty: easy | βœ… Correct: B

πŸ“– Explanation: Run-time cost refers to the CPU time and system resources consumed while the operating system is running the detection logic and updating the necessary data structures during normal operation.

Q31. If a system rarely experiences deadlocks, which approach might be most efficient?

A.Strict Prevention
B.Complex Avoidance
C.Detection and Recovery βœ…
D.Manual Intervention
πŸ’‘ Difficulty: hard | βœ… Correct: C

πŸ“– Explanation: If deadlocks are rare, the overhead of constant prevention or avoidance checks may outweigh the occasional cost of detection and recovery. Allowing the system to run freely and only intervening when a deadlock actually occurs can be more efficient overall.

Q32. What does the edge direction in a Wait-For Graph represent?

A.Resource flow
B.Waiting dependency βœ…
C.Process creation
D.Memory allocation
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: An edge from Pi to Pj represents a waiting dependency: Pi is dependent on Pj releasing a resource before Pi can proceed.

Q33. Why is recovery considered to have potential losses"?"

A.It always crashes the system.
B.It may require aborting processes, losing their computed results. βœ…
C.It deletes all files.
D.It formats the hard drive.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: Recovering from deadlock often involves selecting a victim" process to terminate or roll back. Any work done by that process since its last checkpoint is lost, representing a loss to the user or system."

Q34. Which of the following is true about the Resource-Allocation Graph?

A.It contains only processes.
B.It contains only resources.
C.It contains both processes and resources. βœ…
D.It contains neither.
πŸ’‘ Difficulty: easy | βœ… Correct: C

πŸ“– Explanation: A standard Resource-Allocation Graph includes nodes for both processes (usually circles) and resources (usually squares/rectangles), connected by request and assignment edges.

Q35. What is the benefit of using a Wait-For Graph over a Resource-Allocation Graph for detection in single-instance systems?

A.It shows more detail.
B.It simplifies cycle detection by removing resource nodes. βœ…
C.It works for multiple instances.
D.It requires more memory.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: By removing resource nodes, the WFG reduces the graph size and complexity. Cycle detection algorithms can run faster on a graph with fewer nodes, making it more efficient for single-instance deadlock detection.

Q36. If a system uses detection, when is the detection algorithm typically executed?

A.Continuously in real-time.
B.Periodically or when a request cannot be granted immediately. βœ…
C.Only at startup.
D.Never.
πŸ’‘ Difficulty: hard | βœ… Correct: B

πŸ“– Explanation: Running detection continuously is expensive. Systems often run it periodically (e.g., every hour) or trigger it when a process has been waiting for a resource for a certain threshold time, balancing overhead with timely detection.

Q37. What is the relationship between Prevention, Avoidance, and Detection?

A.They are used together.
B.They are alternative strategies for handling deadlocks. βœ…
C.Detection is part of Prevention.
D.Avoidance is part of Detection.
πŸ’‘ Difficulty: medium | βœ… Correct: B

πŸ“– Explanation: These are three distinct approaches to dealing with deadlocks. A system typically chooses one primary strategy: either prevent them, avoid them, or allow them and detect/recover. They are alternatives, not usually combined components of a single mechanism.

πŸ”— Related Topics (MCQs)