A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Deadlock Detection and Recovery

College Depth 107 in the knowledge graph ☐ I know this ☆ Set as goal
2topics build on this
423prerequisites beneath it
See this on the map →
Deadlock Conditions and Resource Graphs→→Deadlock Prevention and Avoidance Strategies
deadlock detection recovery resource-allocation

Core Idea

Deadlock detection uses resource allocation graphs to identify cycles, indicating deadlock. The OS periodically checks for cycles. Recovery involves terminating processes (simple but destructive) or preempting resources (complex but less disruptive). Detection-and-recovery trades off prevention overhead for acceptance of occasional deadlocks.

Explainer

From deadlock conditions and resource allocation graphs, you know that deadlock requires four conditions — mutual exclusion, hold and wait, no preemption, and circular wait — and that a cycle in the resource allocation graph proves deadlock exists for single-instance resources. Deadlock detection and recovery is the strategy of letting deadlocks happen and then cleaning up, as opposed to preventing or avoiding them in advance.

The detection algorithm works by constructing and analyzing the wait-for graph, a simplified version of the resource allocation graph that shows only which processes are waiting for which other processes. For single-instance resource types, finding a cycle in this graph is sufficient to confirm deadlock. For multi-instance resource types, the detection algorithm is more involved: it simulates resource allocation using available resources, marking processes that could finish with what is currently free, then releasing their resources and repeating. Any process that cannot be marked by the end of this simulation is deadlocked. This is essentially the same logic as the Banker's algorithm for avoidance, but run on current state rather than projected future state.

A critical design question is how often to run the detection algorithm. Running it after every resource request catches deadlocks immediately but adds overhead to every allocation. Running it periodically (say, every few minutes) or when resource utilization drops below a threshold reduces overhead but means deadlocked processes sit idle longer. The right frequency depends on how costly deadlocks are versus how costly detection is — in a system where deadlocks are rare, periodic detection is usually sufficient.

Once a deadlock is detected, the OS must break it. Process termination is the blunt approach: kill one or more deadlocked processes to release their resources. The OS can terminate all deadlocked processes at once (guaranteed to break the deadlock, but maximally destructive) or terminate them one at a time, re-running detection after each kill to see if the deadlock is resolved. Resource preemption is gentler: forcibly take a resource from one process and give it to another, rolling back the victim process to a safe state. This requires the ability to checkpoint and restore process state, which is not always feasible. In either case, the OS must choose a victim — typically the process with the lowest priority, the least accumulated computation, or the one holding the most resources. The detection-and-recovery approach is philosophically pragmatic: rather than constraining every allocation to prevent a rare event, it lets the system run freely and pays the recovery cost only when deadlock actually occurs.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Kernel Architecture and OS Structure → System Calls and User/Kernel Mode → Processes and the Process Control Block → Process Creation: fork() and exec() → Process Termination and Resource Cleanup → Process States and State Transitions → Process Model Formalization → Context Switching and CPU Dispatch → CPU Scheduling Fundamentals → Round-Robin (RR) Scheduling → First-Come-First-Served (FCFS) Scheduling → Scheduling Fairness and Starvation Prevention → Thread Scheduling and Coordination → Semaphores → Deadlock: Conditions and Modeling → Deadlock Conditions and Resource Graphs → Deadlock Detection and Recovery

Longest path: 108 steps · 423 total prerequisite topics

Prerequisites (1)

Leads To (1)