Operating System - Necessary condition for dead lock to occur

For a deadlock to occur in a system, four conditions must hold simultaneously. These are called the Coffman Conditions (named after Edward G. Coffman Jr.).

 1. Mutual Exclusion

  • At least one resource must be non-shareable.

  • Only one process can use the resource at a time.

Example: A printer cannot be shared between two processes simultaneously.

2. Hold and Wait

  • A process is holding at least one resource and is waiting for additional resources that are currently being held by other processes.

Example:
Process A holds a scanner and waits for a printer.
Process B holds the printer and waits for the scanner.

3. No Preemption

  • A resource cannot be forcibly taken from a process; it must be released voluntarily by the process.

Example:
You can’t take back half-printed pages from a process unless it finishes printing.

4. Circular Wait

  • A closed chain of processes exists, where:

    • Each process is waiting for a resource held by the next process in the chain.

Example:
P1 waits for R2 (held by P2)
P2 waits for R3 (held by P3)
P3 waits for R1 (held by P1) → cycle → deadlock