Operating System
OS Part-1
OS Part-2
- File Concepts and Access methods
- Free Space Management and Allocation methods
- Directory Systems and Protection
- File Organization, Sharing and Implementation issues
- Disk and Drum Scheduling
- I/O Devices Organisation & I/O Buffering
- I/O Hardware, Kernel I/O subsystem and Transforming I/O Requests to Hardware Operations
- Device Drivers and Path Management
- Device Driver Sub Modules and Procedure
- Device Scheduler and Handler
- Interrupt Service Routine (ISR)
- File System in Linux and Windows
OS Part-3
- Process and Process Control Block(PCB)
- Process Scheduling( Preemptive and Non Preemptive)
- Scheduling Algorithms
- Algorithm Evaluation
- Multiple Processor Scheduling
- Real Time Scheduling
- Operations on Processes
- Threads
- Inter-Process Communication
- Precedence Graphs
- Critical Section Problem
- Semaphores
- Classical Problems of Synchronization
- DeadLock
- Deadlock Prevention and Avoidance
- Deadlock Detection and Recovery
- Process Management in Linux
OS Part-4
- Memory Hierarchy in OS
- Concepts of Memory Management
- MFT and MVT
- Logical and Physical Address Space
- Swapping
- Contiguous and Non Contiguous Memory Allocation
- Paging
- Segmentation
- Paging Combined with Segmentation
- Structure and Implementation of Page Table
- Virtual Memory in OS
- Cache Memory Organization
- Demand Paging
- Page Replacement Algorithms
- Allocation of Frames and Thrashing
- Demand Segmentation
OS Part-5
- Distributed Operating System: Introduction and Types
- Distributed OS: Design Issues
- Distributed OS: File System
- Distributed OS: Remote File Access
- Remote Procedure Call(RPC)
- Remote Method Invocation(RMI)
- Distributed Shared Memory
- Parallel Processing and Concurrent Programming
- Security and Threats Protection in Distributed OS
- Security Design Principles and Authentication in Distributed OS
- Sensor Network and Parallel OS
Deadlock in Operating System
Introduction
Deadlock ek aisi situation hoti hai jisme ek ya zyada processes ek dusre ke resources ka wait kar rahe hote hain, lekin wo resources already kisi aur process ke paas hote hain. Iss wajah se ek circular wait create hota hai jisme koi bhi process aage nahi badh sakta.
Example: Sochiye do log ek patli gali me samne se aa rahe hain, aur dono side se chalne ko tayyar nahi hain. Dono ek dusre ka wait kar rahe hain ki pehle kaun side hatega. Agar koi nahi hatega, toh dono wahi ruk jayenge. Yehi ek deadlock hai!
Deadlock Hone Ke Conditions (Coffman’s Conditions)
Deadlock tab hota hai jab yeh 4 conditions ek saath satisfy hoti hain:
-
-> Mutual Exclusion (Ek resource ek time me sirf ek process ko milega)
-
Koi bhi resource share nahi ho sakta, ek samay par sirf ek process use karega.
-
-
-
-> Hold and Wait (Process ek resource ko pakad ke baitha hai aur dusre ka wait kar raha hai)
-
Ek process ek resource hold kiya hai aur dusre ka wait kar raha hai.
-
-
-
-> No Preemption (Resource zabardasti kisi se chhina nahi ja sakta)
-
Ek resource ko forcefully kisi aur process ko nahi diya ja sakta. Process ko khud se release karna hoga.
-
-
-
-> Circular Wait (Processes ek cycle bana leti hain)
-
Agar ek set of processes ek cycle bana le jisme har process ek resource ka wait kar raha ho jo kisi aur process ke paas hai, toh deadlock ho jayega.
-
Agar inme se ek bhi condition tod di jaye, toh deadlock avoid ho sakta hai.
Deadlock Ka Example
Maan lijiye do processes (P1 aur P2) hain aur do resources (R1 aur R2) hain:
-
P1 ke paas R1 hai, lekin use R2 bhi chahiye.
-
P2 ke paas R2 hai, lekin use R1 bhi chahiye.
Ab dono ek dusre ka wait kar rahe hain aur koi bhi aage nahi badh sakta. Deadlock ho gaya!
Deadlock Ko Represent Karne Ke Liye Resource Allocation Graph (RAG)
P1 → R1
P2 → R2
P1 ⟶ R2
P2 ⟶ R1
Agar graph me cycle ban jaye, toh deadlock confirm hai!
Deadlock Ko Handle Karne Ke Tarike
1. Deadlock Prevention (Deadlock hone se pehle rokna)
Agar hum 4 conditions me se koi ek tod de, toh deadlock nahi hoga:
-
-> Mutual Exclusion Break Karna → Resources sharable hone chahiye.
-
-> Hold and Wait Ko Avoid Karna → Process ko saare resources ek saath request karne chahiye.
-
-> Preemption Allow Karna → Agar zarurat ho, toh resource forcefully le lena chahiye.
-
-> Circular Wait Avoid Karna → Ek fixed order hona chahiye ki kaunsa resource pehle milega.
2. Deadlock Avoidance (Deadlock hone se pehle check karna)
-
System hamesha pehle check karega ki resource dene se deadlock ho sakta hai ya nahi.
-
Banker’s Algorithm isi kaam ke liye use hota hai.
3. Deadlock Detection & Recovery (Deadlock hone ke baad handle karna)
-
Deadlock Detect Karna → Resource Allocation Graph me cycle ko check karna.
-
Deadlock Solve Karna (Recovery):
-
Kisi ek process ko terminate karna jo deadlock me fasa hai.
-
Resource ko forcefully chhuda kar kisi aur process ko dena.
-
Conclusion
Deadlock tab hota hai jab multiple processes resources ke wait me atak jate hain aur ek circular wait bana lete hain.
Deadlock ko prevention, avoidance, ya detection & recovery se solve kiya jata hai.
Banker’s Algorithm ka use deadlock avoid karne ke liye hota hai.