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
Classical Problems of Synchronization in Operating System
Introduction
Operating System me process synchronization ek important concept hai jo ensure karta hai ki multiple processes ya threads ek sath kaam kare bina kisi conflict ke.
Synchronization problems ko real-world concurrency issues ko samajhne ke liye define kiya gaya hai. Yeh problems semaphores, monitors, aur mutex locks ka use karke solve ki ja sakti hain.
1. Producer-Consumer Problem
Problem Statement:
-
Ek buffer hai jisme producer process items produce karke store karta hai.
-
Consumer process items consume karta hai buffer se.
-
Agar buffer full ho jaye to producer naye items nahi daal sakta.
-
Agar buffer empty ho jaye to consumer naye items nahi nikal sakta.
-
Dono processes ek sath buffer ko access na kare taki data inconsistency na ho.
Solution Using Semaphores:
Is problem ko solve karne ke liye 3 semaphores use hote hain:
-
Mutex → Buffer ka mutual exclusion ensure karta hai.
-
Full → Kitne slots occupied hain ye count karta hai.
-
Empty → Kitne slots free hain ye count karta hai.
Producer Process:
wait(empty); // Agar buffer full hai to wait karega
wait(mutex); // Lock buffer
// Item buffer me add karega
signal(mutex); // Buffer unlock karega
signal(full); // Consumer ko notify karega
Consumer Process:
wait(full); // Agar buffer empty hai to wait karega
wait(mutex); // Lock buffer
// Item buffer se remove karega
signal(mutex); // Buffer unlock karega
signal(empty); // Producer ko notify karega
2. Dining Philosophers Problem
Problem Statement:
-
5 philosophers ek gol table pe baithe hain aur unke samne spaghetti ka bowl hai.
-
Har philosopher ko 2 forks chahiye (ek left aur ek right) khane ke liye.
-
Sirf 5 forks available hain.
-
Agar sare philosophers ek fork utha le aur dusre ke wait kare, to deadlock ho sakta hai.
Solution Using Semaphores:
Har fork ko ek semaphore se represent kiya jata hai jo initially 1 hota hai.
wait(fork[i]); // Left fork uthayega
wait(fork[(i+1)%5]); // Right fork uthayega
// Khana khayega
signal(fork[i]); // Left fork wapas rakhega
signal(fork[(i+1)%5]); // Right fork wapas rakhega
Deadlock Prevention Strategies:
-
Ek time pe maximum 4 philosophers hi forks utha sakein.
-
Ek philosopher pehle right fork uthaye, baaki pehle left fork uthaye.
3. Readers-Writers Problem
Problem Statement:
-
Ek shared database hai jise multiple readers aur writers access kar rahe hain.
-
Readers ek sath database read kar sakte hain.
-
Writers tab tak write nahi kar sakte jab tak koi reader ya writer database access kar raha ho.
Solution Using Semaphores:
-
Mutex → Reader count update karne ke liye.
-
WriteLock → Writer ko exclusive access dene ke liye.
Reader Process Logic:
wait(mutex); // Reader count update karne ke liye lock
readerCount++;
if (readerCount == 1) wait(writeLock); // Pehla reader writers ko block karega
signal(mutex); // Lock release karega
// Read operation
wait(mutex);
readerCount--;
if (readerCount == 0) signal(writeLock); // Last reader writer ko access dega
signal(mutex);
Writer Process Logic:
wait(writeLock); // Database lock karega
// Write operation
signal(writeLock); // Database unlock karega
4. Sleeping Barber Problem
Problem Statement:
-
Ek barbershop hai jisme ek barber aur kuch waiting chairs hain.
-
Agar koi customer nahi hai, to barber so jata hai.
-
Agar customer aata hai, to wo barber ko uthata hai.
-
Agar sab chairs full hain, to naye customers chale jate hain.
-
Challenge ye hai ki customers aur barber ko efficiently manage kiya jaye.
Solution Using Semaphores:
-
Mutex → Waiting room access control karta hai.
-
Customers → Customers ka count track karta hai.
-
Barbers → Barber available hai ya nahi ye track karta hai.
Customer Process Logic:
wait(mutex);
if (waiting < chairs) {
waiting++;
signal(customers); // Barber ko uthayega
signal(mutex);
wait(barber); // Haircut lega
} else {
signal(mutex); // Agar chairs full hain to chala jayega
}
Barber Process Logic:
wait(customers); // Customer ka wait karega
wait(mutex);
waiting--;
signal(mutex);
signal(barber); // Haircut start karega
// Haircut karega
Conclusion
Synchronization problems real-world concurrency issues ko represent karti hain.
Semaphores, mutex locks, aur monitors ka use karke safe execution ensure kiya jata hai.
Deadlocks aur starvation avoid karne ke liye proper handling zaroori hoti hai.