📝 Deadlock Detection in Operating System (37 MCQs)
📖 From Operating System • 7. Deadlocks • 37 questions available
What is Deadlock Detection in Operating System?
Definition:
Deadlock detection allows the system to enter deadlock states but periodically runs an algorithm to identify deadlocked processes and initiate recovery.
Example:
A detection routine executes every milliseconds, examining the current allocation state to determine if set is deadlocked.
Reason:
Detection trades occasional deadlock occurrence for reduced runtime overhead during normal operation, optimizing performance when deadlocks are rare.
📝 All Deadlock Detection in Operating System MCQs
Q1. When is a deadlock detection scheme typically employed?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 Explanation: In a WFG, an edge means that process is blocked, waiting for a resource that is currently allocated to (held by) process .
Q14. If a Wait-For Graph contains a cycle, what does it indicate?
📖 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?
📖 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"?"
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?"
📖 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?
📖 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?
📖 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"?"
📖 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?
📖 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?
📖 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?
📖 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?
📖 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.