OS Notes
Comprehensive comparison of all CPU scheduling algorithms including FCFS, SJF, Priority, Round Robin, and Multilevel Queue with performance analysis, use cases, and selection criteria.
Introduction
Now that you have studied individual scheduling algorithms, a natural question arises: which one should you use? The answer, as with most things in computer science, is "it depends." Each algorithm excels in specific scenarios and fails in others. A batch processing server needs different scheduling than an interactive desktop, which needs different scheduling than a real-time embedded system.
This page provides a comprehensive comparison of all major CPU scheduling algorithms, helping you understand when to use each one, their tradeoffs, and how modern operating systems combine them.
Head-to-Head Comparison Table
| Criterion | FCFS | SJF | Priority | Round Robin | MLFQ |
|---|---|---|---|---|---|
| Selection Basis | Arrival order | Burst time | Priority value | Time quantum | Adaptive behavior |
| Preemptive? | No | Both versions | Both versions | Yes (always) | Yes |
| Starvation | No | Yes (long jobs) | Yes (low priority) | No | No (with boost) |
| Overhead | Minimal | Medium (sorting) | Medium | High (context switches) | Highest |
| Avg Waiting Time | High | Optimal (minimum) | Variable | Medium | Good |
| Response Time | Poor | Poor (non-preemptive) | Variable | Excellent | Excellent |
| Throughput | Low-Medium | High | Variable | Medium | High |
| Fairness | Fair (arrival order) | Unfair to long jobs | Unfair to low priority | Very fair | Fair |
| Complexity | Very simple | Moderate | Moderate | Simple | Complex |
| Predictability | Predictable | Unpredictable | Predictable (by priority) | Predictable | Least predictable |
Performance Analysis with Same Dataset
Let us compare all algorithms using identical processes:
| Process | Arrival | Burst |
|---|---|---|
| P1 | 0 | 8 |
| P2 | 1 | 4 |
| P3 | 2 | 2 |
| P4 | 3 | 1 |
FCFS Result
SJF (Non-Preemptive) Result
SJF (Preemptive / SRTF) Result
| Time 0 | P1 runs (rem=8, only process) |
| Time 1 | P2 arrives (burst=4). P1 rem=7. 4<7, preempt. P2 runs. |
| Time 2 | P3 arrives (burst=2). P2 rem=3. 2<3, preempt. P3 runs. |
| Time 3: P4 arrives (burst=1). P3 rem=1. 1=1, no preempt (tie | current stays). P3 runs. |
| Time 4 | P3 done. Ready: P4(1), P2(3), P1(7). P4 runs. |
| Time 5 | P4 done. Ready: P2(3), P1(7). P2 runs. |
| Time 8 | P2 done. P1 runs. |
| Time 15 | P1 done. |
| Avg Waiting Time | (7+3+0+1)/4 = 2.75 ms ← Best! |
Round Robin (quantum = 3) Result
Key Insight: No Universal Winner
From the analysis above:
- SRTF gives best average waiting time (2.75ms) — optimal
- Round Robin gives best response time (3.0ms) — most interactive
- FCFS gives worst performance (7.0ms waiting) — but simplest
The right choice depends on your system goals.
When to Use Each Algorithm
FCFS — Use When:
- Batch processing systems (no user waiting at terminal)
- All processes have similar burst times
- Simplicity is more important than performance
- Example: Print queue, nightly backup jobs
SJF — Use When:
- Burst times are known or predictable
- Minimizing average waiting time is the primary goal
- Starvation of long jobs is acceptable
- Example: Job shop scheduling with known processing times
Priority Scheduling — Use When:
- Different processes have genuinely different importance levels
- Real-time systems with hard deadlines
- System processes must always preempt user processes
- Example: Hospital patient scheduling, military systems
Round Robin — Use When:
- Interactive/time-sharing systems
- Fairness is the primary concern
- Response time matters more than throughput
- Example: Desktop OS serving multiple users, web servers
MLFQ — Use When:
- Mix of interactive and batch processes
- Process behavior is unknown in advance
- Need both good response time and good throughput
- Example: General-purpose operating systems (Windows, Linux, macOS)
How Modern OS Combine Algorithms
Real operating systems never use a single algorithm in isolation. They combine multiple approaches:
| │ Level 1 | Real-Time Queue │ |
| │ Algorithm | Fixed Priority + FCFS/RR │ |
| │ Processes | Audio drivers, video playback │ |
| │ Level 2 | System/Kernel Queue │ |
| │ Algorithm | Priority Scheduling │ |
| │ Processes | Kernel threads, critical daemons │ |
| │ Level 3 | Interactive Queue │ |
| │ Algorithm | MLFQ with dynamic priority │ |
| │ Processes | GUI apps, terminals, browsers │ |
| │ Level 4 | Batch/Background Queue │ |
| │ Algorithm | FCFS or large-quantum RR │ |
| │ Processes | Compilation, indexing, backups │ |
Linux CFS
Linux's CFS does not use traditional queues. Instead, it assigns each process a virtual runtime that increases as it runs. The process with the lowest virtual runtime runs next. High-priority (low-nice) processes accumulate virtual runtime more slowly, so they run more often. This elegant approach combines fairness with priority support.
Windows Scheduler
Windows uses 32 priority levels with Round Robin within each level. It dynamically boosts priorities for GUI interaction, I/O completion, and starvation prevention. This is essentially a sophisticated MLFQ.
Exam Tips
When asked to compare algorithms in an exam:
- Always calculate actual numbers for the given dataset
- State which metric you are optimizing for
- Mention the tradeoffs (starvation, overhead, predictability)
- For "which algorithm should you use" questions, ask what the system requirements are
Key Takeaways
- No single scheduling algorithm is best for all scenarios — selection depends on system goals
- SRTF is provably optimal for average waiting time but impractical (needs future knowledge)
- Round Robin excels at response time and fairness for interactive systems
- MLFQ adaptively approximates optimal behavior without advance knowledge
- Modern OS combine multiple algorithms in a multilevel structure
- The fundamental tradeoff is between throughput (favor long uninterrupted runs) and response time (favor frequent short runs)
- Real systems also consider power consumption, cache efficiency, and NUMA topology in scheduling decisions
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Scheduling Algorithm Comparison.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, cpu, scheduling, algorithm, comparison
Related Operating Systems Topics