Study and Productivity

CPU Scheduling Algorithms Explained with Gantt Charts (FCFS, SJF, SRTF, RR)

Learn how FCFS, SJF, SRTF, priority and round robin scheduling work, how to draw the Gantt chart and how to calculate waiting and turnaround times.

Saizul Amin
Saizul Amin3 Nov 2026 · 4 min read
CPU Scheduling Algorithms Explained with Gantt Charts (FCFS, SJF, SRTF, RR)

CPU Scheduling Algorithms Explained with Gantt Charts (FCFS, SJF, SRTF, RR)

A computer usually has more ready programs than processor cores. The CPU scheduler decides which process runs next, and that choice affects how fast programs finish and how responsive the system feels. Operating systems courses test this with a familiar question: here is a table of processes, draw the Gantt chart and find the average waiting time. This guide shows how to answer it for each algorithm, with the free CPU scheduling simulator to check every step.

The vocabulary

Each process has an arrival time (when it becomes ready) and a burst time (how much CPU it needs). From the Gantt chart you read its completion time, then:

  • Turnaround time = completion − arrival
  • Waiting time = turnaround − burst
  • Response time = first time on the CPU − arrival

Write these three formulas at the top of your answer; most lost marks come from mixing them up.

First come, first served (FCFS)

Run processes in arrival order, each to completion.

P1 (0, 24), P2 (0, 3), P3 (0, 3):

  • Gantt: P1 0–24, P2 24–27, P3 27–30
  • Waiting: 0, 24, 27 → average 17

If P2 and P3 had gone first, the average would be 3. Short jobs stuck behind a long one is called the convoy effect.

Shortest job first (SJF)

When the CPU is free, pick the ready process with the smallest burst and run it to completion. With P1 (0, 6), P2 (0, 8), P3 (0, 7), P4 (0, 3), the order is P4, P1, P3, P2 and the average waiting time is 7. SJF gives the lowest average waiting time of any non-preemptive method.

Shortest remaining time first (SRTF)

The preemptive version: whenever a process arrives, compare its burst with the remaining time of the running process, and switch if it is shorter.

P1 (0, 8), P2 (1, 4), P3 (2, 9), P4 (3, 5):

  1. 0–1: P1 runs (only one ready).
  2. At 1, P2 (4) beats P1's remaining 7: P2 runs 1–5.
  3. At 5, shortest remaining is P4 (5): runs 5–10.
  4. P1 (7 left) runs 10–17, then P3 runs 17–26.

Waiting: P1 = 17 − 0 − 8 = 9, P2 = 0, P3 = 26 − 2 − 9 = 15, P4 = 10 − 3 − 5 = 2. Average 6.5.

The simulator's table writes these subtractions out, so you can compare line by line.

Priority scheduling

Each process has a priority; here a lower number means more important. Non-preemptive priority picks the best priority when the CPU is free; the preemptive version lets a more important arrival interrupt. The danger is starvation: a low-priority process may never run. Real systems fix this with ageing, slowly improving the priority of waiting processes.

Round robin (RR)

Each process gets at most one time quantum, then goes to the back of the queue.

P1 (0, 24), P2 (0, 3), P3 (0, 3) with quantum 4:

  • P1 0–4, P2 4–7, P3 7–10, P1 10–30
  • Waiting: P1 = 6, P2 = 4, P3 = 7 → average 5.67

Two details cause most errors:

  1. When a process arrives during a time slice and the running process is preempted at the end of that slice, the new arrival joins the queue first. This is the convention in most textbooks and in the simulator.
  2. A process that finishes before its quantum ends gives up the CPU immediately.

The quantum matters: too small and the CPU wastes time switching; too large and round robin behaves like FCFS.

Comparing algorithms

The simulator's compare tab runs all six algorithms on the same processes. Typically:

  • SRTF has the lowest average waiting time but needs burst times in advance and can starve long jobs.
  • Round robin has the best response time, which is what interactive users notice.
  • FCFS is simple and fair in order, but suffers the convoy effect.

Exam checklist

  • Draw the Gantt chart with times under every boundary, including idle gaps.
  • Note the tie-breaking rule (arrival, then process number).
  • Calculate turnaround and waiting for each process in a table, then average.
  • For RR, keep a written queue at each time step.

Limits

The simulator models one CPU with no I/O and no context-switch cost, the standard textbook setting. Real schedulers use multilevel feedback queues, multiple cores and dynamic priorities, and conventions for ties differ between books.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages