A-Level · Operating Systems

CPU Scheduling Algorithms

One CPU, several processes wanting to run. The scheduling algorithm decides who goes next, and that single decision has real consequences: how long processes wait, how responsive the system feels, and whether short jobs get stuck behind long ones. Every chart below uses the exact same four processes, so the differences you see are genuinely down to the algorithm, nothing else.

Section 2

First Come First Served (FCFS)

The simplest possible rule: whoever arrives first runs first, all the way to completion, no interruptions. Step through it and watch what happens to C.

Currently running
–
Ready queue (arrived, waiting)

Controls

Exam tips

  • FCFS suffers from the convoy effect: a single long process at the front makes every shorter process behind it wait far longer than its own burst time would suggest, exactly what happens to C here, a 1-unit job waiting 7 units purely due to arrival order.
  • Non-preemptive: once a process starts, nothing can interrupt it, no matter what arrives afterward.
Section 3

Shortest Job First (SJF)

Instead of arrival order, pick whichever available process has the shortest burst time. Still non-preemptive, once chosen, a process runs to completion.

Currently running
–
Ready queue (arrived, waiting)

Controls

Exam tips

  • SJF needs to know each process's burst time in advance, in a real OS this is usually an estimate, not a certainty, which is a genuine practical limitation.
  • Notice A still runs first here, at t=0 it's the only available process, SJF can only choose among processes that have already arrived, it can't see the future.
Section 4

Shortest Remaining Time (SRT)

The preemptive version of SJF: at every single moment, run whichever process has the least time left, even if that means interrupting something already running. This one steps one time unit at a time, so you can watch the exact instant a preemption happens and see why.

Currently running
–
Remaining time (all arrived processes)

Controls

Exam tips

  • This is the same process set as FCFS, but A now gets split into two separate runs, genuinely interrupted, not just naturally handed over. Every time a new process arrives, the scheduler re-checks whether it's now shorter than whatever's currently running.
  • SRT generally gives the best possible average waiting time of any of these algorithms, but constant preemption has a real cost: switching between processes isn't free, it takes time the CPU could otherwise spend computing.
Section 5

Round Robin

Every process gets a fixed time slice, called a quantum, then moves to the back of the queue if it hasn't finished. Nobody waits forever, but nobody gets to hog the CPU either.

Currently running (quantum = 2)
–
Queue, front to back

Controls

Exam tips

  • Quantum size matters enormously: too large and Round Robin starts behaving like FCFS, too small and the CPU wastes time constantly switching between processes instead of actually computing.
  • Round Robin's average waiting time here (5.25) is actually worse than FCFS's, that's a genuinely important point: fairness and responsiveness are not the same goal as minimising average wait, and Round Robin optimises for the former.
Section 6

Multi-Level Feedback Queue (MLFQ)

Two queues this time: a high-priority queue running Round Robin with a short quantum, and a low-priority queue running FCFS. Every process starts in the high-priority queue, if it doesn't finish within its quantum, it gets demoted. Watch the process chips actually move from the Q0 box down into the Q1 box.

Currently running
–

Controls

Q0, high priority (Round Robin, quantum = 2)
Q1, low priority (FCFS, runs to completion)

Exam tips

  • Notice C, the shortest job, finishes entirely within the high-priority queue and never gets demoted at all, MLFQ tends to favour short jobs without needing to know burst times in advance the way SJF and SRT do.
  • The high-priority queue always takes precedence: if anything is waiting in Q0, it runs before anything in Q1 gets a turn, no matter how long that Q1 process has already been waiting.
Section 7

Head to head: same processes, five outcomes

Every algorithm above ran the exact same four processes. Here's what that actually cost each process, and each algorithm, on average.

Lowest average waiting time is highlighted. Notice there's no single "best" algorithm in every sense, SRT wins on average wait but needs preemption and future knowledge, FCFS is simplest but suffers the convoy effect, Round Robin trades average wait for guaranteed fairness.

Section 8

Check your understanding