# CPU Scheduling

> Compare FCFS, SJF, SRTF, Priority and Round Robin scheduling, compute waiting and turnaround times, and understand starvation and aging. Free notes, key...

Canonical: https://www.internhack.in/roadmaps/tracks/cs-fundamentals/cpu-scheduling
Last updated: 2026-11-28

Compare FCFS, SJF, SRTF, Priority and Round Robin scheduling, compute waiting and turnaround times, and understand starvation and aging.

Beginner · about 5 hours · difficulty 2/5

Learn first: [Processes and Threads](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/processes-and-threads)

The scheduler decides which ready process runs next. Placement tests love numerical scheduling problems, so practise the Gantt charts until they are mechanical.

### Metrics

- **Arrival time**, **burst time**, **completion time**.
- **Turnaround time** = completion - arrival. **Waiting time** = turnaround - burst. **Response time** = first run - arrival.
- **Throughput** and **CPU utilisation** at the system level.

### Algorithms

- **FCFS**: simple queue, non-preemptive. Suffers from the **convoy effect** when a long job blocks short ones.
- **SJF**: shortest burst first, optimal average waiting time, but needs burst estimates and can starve long jobs. **SRTF** is its preemptive version.
- **Priority scheduling**: preemptive or not. Low-priority jobs can **starve**; **aging** gradually raises their priority.
- **Round Robin**: each process gets a **time quantum**. Too small means excessive context switches; too large degrades to FCFS. Good response time for interactive systems.
- **Multilevel queue** and **multilevel feedback queue**: separate queues for interactive and batch jobs, with processes moving between levels based on behaviour. Real OSes use variants of this.

### How to solve numericals

Draw a timeline, track the ready queue at each arrival or completion, and fill a table with CT, TAT and WT. For Round Robin, be careful about the order when a new process arrives at the same moment another's quantum expires (state your assumption).

### Also know

Preemptive vs non-preemptive scheduling, CPU-bound vs I/O-bound processes, and the idea behind Linux's Completely Fair Scheduler (optional).

Good enough to move on: you can solve a five-process Round Robin and SRTF question correctly in under ten minutes.

## Key concepts

- **Turnaround, waiting and response time**
- **FCFS and convoy effect**
- **SJF and SRTF**
- **Priority scheduling and aging**
- **Round Robin and time quantum**
- **Multilevel feedback queues**
- **Linux CFS basics**

## Mini project

Write a scheduling simulator that reads processes (arrival, burst, priority) and prints the Gantt chart plus average waiting and turnaround time for FCFS, SJF, SRTF, Priority and Round Robin, then compare results on the same input.

## Check yourself

Why does SJF give the minimum average waiting time, and what practical problems stop an OS from using it directly?

## Free resources

- [OSTEP: Scheduling chapters](https://pages.cs.wisc.edu/~remzi/OSTEP/) (OSTEP)
- [GeeksforGeeks: CPU Scheduling in Operating Systems](https://www.geeksforgeeks.org/cpu-scheduling-in-operating-systems/) (GeeksforGeeks)

Previous: [Processes and Threads](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/processes-and-threads) · Next: [Concurrency and Synchronization](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/concurrency-synchronization)

## More in Operating Systems

- [Processes and Threads](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/processes-and-threads)
- [CPU Scheduling](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/cpu-scheduling)
- [Concurrency and Synchronization](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/concurrency-synchronization)
- [Deadlocks](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/deadlocks)
- [Memory Management and Virtual Memory](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/memory-management)
- [File Systems, Storage and I/O](https://www.internhack.in/roadmaps/tracks/cs-fundamentals/file-systems-and-io)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [CS Fundamentals and Placement Prep Roadmap](https://www.internhack.in/roadmaps/tracks/cs-fundamentals)
