0% found this document useful (0 votes)
13 views13 pages

Unit Deadlock

Uploaded by

sameermehta428
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views13 pages

Unit Deadlock

Uploaded by

sameermehta428
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

What is deadlock

A deadlock ek aisi state hoti hai concurrent computing mein jab multiple processes indefinitely block ho jaati hain kyunki wo ek
dusre ke resources ke liye circular waiting mein fas jaati hain. Har process apna resource hold karti hai lekin dusre process ke
resource ka wait karti hai, jis wajah se execution halt ho jaata hai.

💡 Technical Example:
Maan lo do processes hain: P1P_1P1​aur P2P_2P2​, aur do resources: R1​aur R2​.
•P1ne R1​ko lock kar liya aur R2​ka wait kar raha hai.
•P2​ne R2​ko lock kar liya aur R1​ka wait kar raha hai.
Blocked Process:
•Agar process blocked ho gayi aur resource free nahi ho raha hai, to process deadlock me fass jati hai.
•Forever loop me phase rehti hai kyunki wo resource ka wait karti rehti hai jo kabhi free nahi hota.
✅ Single Instance vs Multi-Instance in Deadlock
1.Single Instance:
1. Ek single copy hoti hai resource ki jo ek baar me sirf ek process use kar sakti hai.
2. Agar ek process ne resource le liya, to doosri process ko wait karna padega jab tak pehli process resource free na kare.
3. Example:
1. Printer: Ek samay me sirf ek process print kar sakti hai.
2. CD-ROM: Ek process hi access kar sakti hai.
2.Multi-Instance:
1. Ek resource ki multiple copies hoti hain jo alag-alag processes use kar sakti hain.
2. Multiple processes simultaneously resource access kar sakti hain.
3. Example:
1. Memory blocks: Multiple processes memory use kar sakti hain.
2. CPU cores: Multi-core processors me alag processes alag cores par chal sakti hain.

✅ Deadlock ke Necessary Conditions


A deadlock ek aisi state hoti hai concurrent computing mein jab multiple processes indefinitely block ho jaati hain kyunki wo ek
dusre ke resources ke liye circular waiting mein fas jaati hain. Har process apna resource hold karti hai lekin dusre process ke
resource ka wait karti hai, jis wajah se execution halt ho jaata hai.
1. Mutual Exclusion
•Mutual exclusion ka matlab hai ki resources non-shareable mode me hone chahiye, yaani ek waqt par sirf ek process hi resource ko access
kar sakti hai.
•Agar koi doosri process usi resource ko request karti hai, toh use wait state me daal diya jata hai jab tak pehli process resource ko release na
kare.

Technical Diagram:

P1 → R1 (Hold) P2 → R1 (Wait)
•Yaha P1 ne R1 ko acquire kar liya hai.
•P2 usi resource ko request kar rahi hai, par usse wait state me bhej diya jata hai.
•Kyunki resource non-shareable hai, isliye mutual exclusion condition satisfy hoti hai.
2. Hold and Wait
•Hold and wait tab hota hai jab koi process ek resource hold karti hai aur saath hi doosre resource ka wait karti rehti hai.
•Is condition me process kuch resources ko allocate karke doosre resources ka wait karti hai, jis wajah se resource
dependency create hoti hai.
Technical Diagram:
P1 ne R1 hold kiya hai, lekin wo R2 ka wait kar rahi hai.

3. No Preemption
•No preemption ka matlab hai ki resources ko forcibly release nahi kiya ja sakta.
•Ek baar jab koi process resource acquire kar leti hai, toh wo usse voluntarily release karne tak resource ko hold karti rehti hai.
•OS us resource ko forcefully reclaim nahi kar sakta.

Technical Diagram:

P1 → R1 (Hold) P2 → R1 (Request → Wait)


•P1 ne R1 acquire kiya hai.
•P2 bhi R1 ko request karti hai, lekin kyunki preemption allowed nahi hai, P2 ko wait state me bhej diya jata hai.
•No preemption hone se processes indefinitely wait kar sakti hain, jo deadlock cause karta hai.
4. Circular Wait
•Circular wait tab hota hai jab multiple processes circular chain me fas jati hain.
•Yani, har process agli process ke paas available resource ka wait kar rahi hoti hai, lekin chain kabhi complete nahi hoti, jis
wajah se koi bhi process apna kaam complete nahi kar pati.

Technical Diagram:
Resource Allocation Graph (RAG) – Definition in Hinglish
Resource Allocation Graph (RAG) ek directed graph hai jo operating system me processes aur resources ke allocation ko
represent karta hai. Isme process nodes (circle), resource nodes (square), request edges (process → resource), aur assignment
edges (resource → process) hote hain. RAG ka main use deadlock detection ke liye hota hai, jisme agar graph me cycle present
ho, to deadlock hone ki sambhavana hoti hai.
Processes (Pi)
•Circle (गोल) se represent kiya gaya hai
••.Processes resources ki request kar sakte hain ya unhe hold kar sakte hain.

•Resources (Ri, Rj)


•Square (चौकोर) se represent kiya gaya hai.
•Har resource Single Instance (S.I) ya Multiple Instances (M.I) me ho sakta hai.

•Edges (Arrows - तीर/लाइन)


•Claim Edge (Dashed Arrow - टूटी हुई लाइन) → Dikhata hai ki process future me resource ki demand kar sakta ha
•Request Edge (Solid Arrow: Process → Resource) → Jab ek process resource ki request karta hai.
•Assignment Edge (Solid Arrow: Resource → Process) → Jab ek resource allocate ho jata hai process ko.
Key Observations from the Image
1. Left Graph (G₁ - Deadlock Situation)
•Cycle Present Hai:
• Processes aur resources ke beech ek circular wait hai:
• P1→R1→P2→R3→P3→R2→P1
• Iska matlab har process ek aise resource ka wait kar raha hai jo kisi aur process ne hold kiya hai.
• Result: System deadlock me phasega, aur koi bhi process execute nahi ho paayega.

2. Right Graph (G₂ - No Deadlock)


•Cycle Break Kar Di Gayi Hai:
• Resource allocation ko modify kiya gaya hai, jisse circular wait condition nahi bani.
• Ab har process ko eventually resource mil jayega aur execution complete hoga.
• Result: System deadlock-free hai ✅
Deadlock Ignorance Kya Hai? (What is Deadlock Ignorance?)
•Definition: Is approach me operating system deadlock ko detect ya prevent nahi karta, kyunki deadlocks rare hote hain aur
unko handle karne ka overhead avoid kiya jata hai.
•General-purpose OS (Windows, Linux, macOS) is strategy ko follow karte hain.
•Agar deadlock ho jaye, toh manual intervention (process ko kill karna ya system restart karna) ki zaroorat hoti hai.

Deadlock Ignorance ke Advantages & Disadvantages


✅ Advantages (Fayde)
•Low Overhead: Koi extra CPU cycles ya memory resource allocation track karne ke liye use nahi hoti.
•Simple Implementation: Koi complex deadlock prevention ya detection algorithm implement nahi karni padti.
•Efficient for General Use Cases: Agar deadlocks rare hain, toh yeh strategy fast aur lightweight hoti hai.
❌ Disadvantages (Nuksan)
•Processes May Hang Indefinitely: Agar deadlock ho jaye toh affected processes hamesha ke liye stuck ho sakti hain jab tak
manually terminate na kiya jaye.
•System Reliability Issues: Critical applications (jaise banking, air traffic control, real-time systems) me deadlock ignore karna
risky ho sakta hai.
•Manual Resolution Required: Deadlocks ko administrator manually resolve karega, jo large-scale distributed systems me
inefficient ho sakta hai.
🔧 Step 4: Deadlock Prevention Strategies (1 by 1)

Deadlock Prevention ek aisi technique hai jisme system ko is tarah design kiya jaata hai ki deadlock hone wali 4 necessary
conditions me se kam se kam ek condition ko break kar diya jaaye, taaki deadlock kabhi ho hi na.

✅ 1. Mutual Exclusion ko Avoid Karna


•Kya karein?:
•Jo resources shareable ho sakte hain (e.g., read-only files), unhe sharable bana do.
•Limitation:
•Kuch resources jaise printer, CPU, etc. non-sharable hote hain. Isliye yeh strategy har jagah possible nahi.

✅ 2. Hold and Wait ko Prevent Karna


•Kya karein?:
•Process ko force karo ki sabhi required resources ek hi baar me maangein.
•Agar available hain to allocate karo, warna process wait kare bina kuch bhi na le.
•Fayda:
•Hold-and-wait condition avoid ho jaati hai.
•Nuksaan:
•Resource utilization kam ho jaata hai.
•Process ko starvation ho sakta hai (kabhi bhi sabhi resources ek saath na milen).
✅ 3. No Preemption ko Break Karna
•Kya karein?:
•Agar process ko koi resource nahi milta, to usse kaha jaata hai ki jo bhi resource uske paas hai wo release karein.
•Baad me dubara try kare.
•Fayda:
•Deadlock ka ek major cause eliminate ho jaata hai.
•Nuksaan:
•Performance slow ho sakti hai due to repeated releases.
•Process ko fir se sab resources collect karne padte hain.

✅ 4. Circular Wait ko Prevent Karna


•Kya karein?:
•Sabhi resources ko ek unique number/order assign karo (e.g., R1 < R2 < R3).
•Process ko bol do ki resources hamesha increasing order me hi maangein.
•Fayda:
•Circular chain ban hi nahi sakti, isliye deadlock impossible ho jaata hai.

You might also like