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 Prevention and Avoidance in Operating System
Deadlock ek aisi situation hoti hai jisme multiple processes ek dusre ka wait karte hain aur system halt ho jata hai (ruk jata hai). Is problem ko solve karne ke liye Deadlock Prevention aur Deadlock Avoidance ka use kiya jata hai.
Deadlock Prevention
Deadlock prevention ka matlab hai ki deadlock hone se pehle hi usko rok diya jaye.
Coffman’s Conditions ke 4 rules hote hain jo deadlock hone ke liye zaroori hote hain:
-
-> Mutual Exclusion (Resource ek samay par sirf ek process ke paas ho)
-
-> Hold and Wait (Process ek resource hold karke dusre ka wait kare)
-
-> No Preemption (Resources zabardasti nahi liye ja sakte)
-
-> Circular Wait (Processes ek cycle me ek dusre ka wait karein)
Deadlock Prevention Ka Tarika
Agar hum in 4 conditions me se koi ek tod de, toh deadlock prevent ho sakta hai.
Coffman’s Condition | Deadlock Prevention Technique |
---|---|
Mutual Exclusion | Jitne ho sake utne resources ko shareable banaya jaye. (Jaise: Read-Only files) |
Hold and Wait | Process ko saare resources ek saath request karne honge ya bina resource hold kiye wait karna hoga. |
No Preemption | Agar ek process ko resource mil gaya hai lekin use complete nahi kar raha, toh system forcefully us resource ko free kar sakta hai. |
Circular Wait | System ek fixed order me resource allocation karega jisse circular wait na bane. |
Example:
Sochiye ek printing system hai jisme Printer aur Scanner dono resources available hain.
-
Without Prevention: Ek process printer lega, dusra scanner le lega, aur dono ek dusre ka wait karenge → Deadlock!
-
With Prevention: System decide karega ki pehle scanner milega phir printer. Isse circular wait break ho jayega.
Deadlock Avoidance
Deadlock avoidance ka matlab hai ki system hamesha check kare ki ek resource assign karne ke baad deadlock hoga ya nahi.
How it Works?
-
Process ko pahle hi batana padega ki usko kitne resources chahiye.
-
System tabhi resource dega jab confirm ho ki koi circular wait nahi hoga.
-
Safe State aur Unsafe State ka concept use hota hai.
Safe State vs Unsafe State
Safe State: Agar system kisi process ko resource deke bhi deadlock avoid kar sakta hai, toh wo safe state me hai.
Unsafe State: Agar system kisi process ko resource deke deadlock me fas sakta hai, toh wo unsafe state me hai.
Example:
Maan lijiye 3 processes (P1, P2, P3) hain aur system ke paas sirf 10 resources hain.
Process | Maximum Need | Already Allocated | Remaining Need |
---|---|---|---|
P1 | 7 | 2 | 5 |
P2 | 6 | 3 | 3 |
P3 | 5 | 2 | 3 |
Agar hum bina check kiye koi bhi resource allocate kar dete hain, toh system unsafe state me chala jayega aur deadlock ho sakta hai.
Banker’s Algorithm (Deadlock Avoidance Technique)
Banker’s Algorithm ek deadlock avoidance technique hai jo check karta hai ki system safe hai ya nahi.
Steps:
-
Har process ko pehle batana hota hai ki usko maximum kitne resources chahiye.
-
Jab bhi ek process resource maangta hai, toh system check karta hai ki agar ye resource de diya jaye toh bhi koi deadlock toh nahi hoga.
-
Agar safe state hai, toh resource de diya jata hai.
Example:
Maan lijiye ek bank hai jisme 5 customers hain aur sirf 10 lakh rupees hain.
-
Agar koi customer poora paisa ek saath le jaye, toh bank bankrupt ho sakta hai.
-
Isliye Banker’s Algorithm ensure karta hai ki paise is tarah allocate kiye jayein ki koi bhi deadlock na ho.
Conclusion
Deadlock Prevention ka matlab hai deadlock hone se pehle hi usko rok dena.
Deadlock Avoidance ka matlab hai pehle check karna ki deadlock hoga ya nahi.
Banker’s Algorithm ek popular deadlock avoidance technique hai jo safe state maintain karta hai.