CPU Scheduling

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

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