Operating SystemProgress: 0/2 completed
Subjects/Operating System

Deadlocks & Coffman Conditions

Medium
15 mins read
Prerequisites
  • Mutex & Semaphore
  • Process Synchronization basics

Introduction

Deadlock ek aisi situation hai computer system me, jahan do ya do se zyada processes block ho jate hain kyunki har ek process us resource ko hold karke baitha hai jo doosre ko chahiye, aur wo kisi aur resource ke release hone ka wait kar raha hai. Yeh simple infinite loop ki tarah hai jisse system freeze ho jata hai.

Real-Life Analogy

💡 Narrow Bridge Crossing

Single lane bridge deadlock

Concept TermReal-life Analogy Mapping
ResourceNarrow Single-lane Bridge
Process ACar coming from Left side
Process BCar coming from Right side
Deadlock StateDono cars bridge ke center me aake face-to-face ruk gayi hain, koi aage-piche nahi ho raha

Detailed Concept Explanation

Deadlock lagne ke liye 4 conditions ka EKSATH (simultaneously) satisfy hona zaroori hai. Inhe Coffman Conditions kehte hain: 1. **Mutual Exclusion**: Kam se kam ek resource non-shareable hona chahiye (ek time pe ek hi process use kar sake). 2. **Hold and Wait**: Process ek resource ko hold karke doosre resource ka request/wait kar raha ho. 3. **No Preemption**: Kisi process se uska resource zabardasti nahi chhina ja sakta. Wo khud hi free karega. 4. **Circular Wait**: Processes ki aisi cycle ban jaye jahan P0, P1 ka wait kar raha hai, P1, P2 ka, and Pn, P0 ka wait kar raha hai.

Visual Diagram

1Mutual ExclusionNo Sharing (1 Resource = 1 Process)
2Hold & WaitResource hold karke doosre ka wait
3No PreemptionZabardasti resource snatching NO
4Circular WaitWaiting chain forms a closed Loop
🚨 Jab ye CHAAR conditions EKSATH lagti hain, tabhi Deadlock hota hai!
Important Point
  • Agar in 4 conditions me se ek bhi condition ko invalid kar dein, toh deadlock kabhi nahi lagega.
  • Resource Allocation Graph (RAG) me cycle hona Single Instance resource case me deadlock confirm karta hai.
  • Deadlock Prevention methods target break of any of the 4 conditions.
Mnemonic / Memory Trick

M-N-H-C (Mere Naal Hasi Chalo)

Mutual exclusion, No preemption, Hold & wait, Circular wait

Mnemonic to easily memorize all four Coffman conditions for deadlocks.
Avoid This Common Mistake
Students confuse overlap: Multi-instance resource system me RAG me cycle hone ka matlab guaranteed deadlock nahi hota. Kyunki resources aur copy options me split ho sakte hain. Single instance resource me cycle = deadlock.
GATE Exam Insights
Banker's Algorithm (Deadlock Avoidance) and Safe Sequence calculation are extremely hot topics for numericals in GATE OS paper.

Practice Mini Quiz

Revision Summary (One-Page Notes)

  • Deadlock is a state of mutual block.
  • Coffman conditions are Mutual Exclusion, Hold & Wait, No Preemption, and Circular Wait.
  • Strategies include Prevention, Avoidance (Banker's Algorithm), Detection, and Recovery.