Deadlock - aryanjoshi0823/5143-Operating-System GitHub Wiki

A deadlock occurs in an operating system when two or more processes are unable to proceed with their execution because each process is waiting for a resource that is held by another process.


In the example below:

  • Process 1 holds Resource 1 and needs Resource 2 to proceed.
  • Process 2 holds Resource 2 and needs Resource 1 to proceed.

Since neither process is willing to release its resource, a deadlock occurs, and both processes are stuck.


Coffman Conditions:

A deadlock occurs if all four Coffman conditions are true simultaneously. These conditions are not mutually exclusive.

1. Mutual Exclusion

  • A resource can only be held by one process at a time.
  • Example: If Process 1 holds Resource 1, no other process can access it until it is released.

2. Hold and Wait

  • A process can hold one or more resources and simultaneously request additional resources held by other processes.
  • Example: Process 2 holds Resource 2 and 3 while requesting Resource 1, which is held by Process 1.

3. No Preemption

  • Resources cannot be forcibly removed from a process.
  • Example: Process 2 cannot preempt Resource 1 from Process 1. The resource will only be released when Process 1 voluntarily completes its task.

4. Circular Wait

  • Processes form a circular chain where each process waits for a resource held by the next process in the chain.
  • Example:
    • Process 1 holds Resource 2 and requests Resource 1.
    • Process 2 holds Resource 1 and requests Resource 2, forming a circular wait.