Deadlock is a situation where a set of processes are blocked permanently, each holding a resource while waiting for one held by another process in the set.
- Occurs only when four necessary conditions hold together at the same time.
- Handled by prevention, avoidance, detection and recovery, or by ignoring it.

Deadlock Handling
Deadlock Handling decides how the operating system deals with deadlocks, either by stopping them from occurring or by recovering after they occur. The main approaches are:

- Conditions for Deadlock: The four conditions, mutual exclusion, hold and wait, no preemption, and circular wait, that must all hold together for a deadlock to occur.
- Deadlock Prevention: Ensures at least one of the four necessary conditions can never hold, so deadlock cannot occur.
- Banker's Algorithm for Deadlock Avoidance: Grants a resource request only if the system stays in a safe state, checked using available, allocated, and maximum need matrices.
- Detection And Recovery: Lets deadlock occur, detects it using a graph or matrix check, then recovers by terminating processes or preempting resources.
- Deadlock Ignorance: Ignores the problem on the assumption that deadlocks are rare, as in the Ostrich Algorithm, saving overhead at the cost of occasional restarts.
Related Concepts
- Starvation and Livelock: Starvation is indefinite waiting for a resource, while livelock keeps processes active but making no progress, unlike deadlock where they stay blocked.
- Dining Philosophers Problem: A classic synchronization problem where philosophers share forks, and deadlock occurs if each picks up one fork and waits for the other.
Quiz: Deadlock in OS