Chapter 2 (Hindi)
3. CPU Scheduling
CPU Scheduling
CPU scheduling वह process है जिसका उपयोग Operating System (OS) यह तय करने के लिए करता है कि किस process को किसी particular time पर CPU मिलेगा।
यह जरूरी है क्योंकि CPU एक समय में केवल एक ही task execute कर सकता है, जबकि कई processes execute होने के लिए ready रहते हैं।
CPU Scheduling के उद्देश्य
- CPU utilization को maximize करना
- Process के response time और waiting time को minimize करना
CPU Scheduling की आवश्यकता
CPU scheduling यह तय करता है कि कौन सा process CPU का उपयोग करेगा जब कोई अन्य process suspended हो।
- इसका मुख्य उद्देश्य यह सुनिश्चित करना है कि CPU idle न रहे।
- OS हमेशा ready queue में से किसी एक process को select करता है ताकि CPU busy रहे।
Terminologies Used in CPU Scheduling
1. Arrival Time
वह समय जब process ready queue में आता है।
2. Completion Time
वह समय जब process अपना execution पूरा करता है।
3. Burst Time
CPU execution के लिए process को जितना समय चाहिए उसे burst time कहते हैं।
4. Turn Around Time (TAT)
Process के complete होने में लगा कुल समय।
👉 Formula:
Turn Around Time = Completion Time – Arrival Time
5. Waiting Time (W.T)
Process के wait करने का समय (ready queue में)।
👉 Formula:
Waiting Time = Turn Around Time – Burst Time
CPU Scheduling Algorithm Design करते समय ध्यान देने योग्य बातें
1. CPU Utilization
- CPU को जितना हो सके उतना busy रखना चाहिए।
- Real system में CPU utilization लगभग 40% से 90% के बीच होता है।
2. Throughput
- प्रति unit time में complete होने वाले processes की संख्या को throughput कहते हैं।
- यह process की length पर depend करता है।
3. Turn Around Time
- Process के arrival से लेकर completion तक का समय।
- इसमें waiting, CPU execution और I/O time शामिल होता है।
4. Waiting Time
- Ready queue में process के wait करने का समय।
- Scheduling algorithm मुख्यतः इसी को affect करता है।
5. Response Time
- Process submit होने से लेकर first response मिलने तक का समय।
- यह interactive systems में अधिक महत्वपूर्ण होता है।
Types of CPU Scheduling Algorithms
1. Preemptive Scheduling
इसमें OS running process को बीच में रोककर दूसरे process को CPU दे सकता है।
- Process running → ready state या waiting → ready state में जा सकता है।
- Example: Priority Scheduling, Round Robin
2. Non-Preemptive Scheduling
इसमें process तब तक CPU पर चलता है जब तक वह पूरा execute न हो जाए या waiting state में न चला जाए।
- Process खुद CPU छोड़ता है।
- Example: FCFS, SJF (non-preemptive)

CPU Scheduling Algorithms
अब हम अलग-अलग CPU scheduling algorithms को एक-एक करके समझते हैं:
- FCFS (First Come First Serve)
- SJF (Shortest Job First)
- SRTF (Shortest Remaining Time First)
- Round Robin (RR)
- Priority Scheduling
- HRRN (Highest Response Ratio Next)
- Multilevel Queue (MLQ)
- Multilevel Feedback Queue (MFLQ)
📊 Comparison of CPU Scheduling Algorithms
| Algorithm | Allocation (कैसे CPU मिलता है) | Complexity | Average Waiting Time (AWT) | Preemption | Starvation | Performance |
|---|---|---|---|---|---|---|
| FCFS | Arrival time के अनुसार | Simple और easy | Large (ज्यादा) | No | No | Slow |
| SJF | Lowest Burst Time (BT) के आधार पर | FCFS से ज्यादा complex | FCFS से कम | No | Yes | Best (minimum waiting time) |
| SRTF | Lowest remaining Burst Time (preemptive) | FCFS से ज्यादा complex | Depend करता है | Yes | Yes | Short jobs को preference |
| Round Robin (RR) | Arrival order + fixed Time Quantum (TQ) | TQ पर depend | SJF से ज्यादा | Yes | No | Fair (equal time) |
| Priority (Preemptive) | Highest priority पहले | कम complex | FCFS से कम | Yes | Yes | Good लेकिन starvation |
| Priority (Non-Preemptive) | Priority के अनुसार execution | और कम complex | FCFS से कम | No | Yes | Batch systems के लिए अच्छा |
| MLQ | Multiple queues की priority के अनुसार | Complex | FCFS से कम | No | Yes | Good लेकिन starvation |
| MFLQ | Dynamic priority queues के आधार पर | सबसे ज्यादा complex | सबसे कम (कई cases में) | No | No | Best performance |