A Level · Topic 16.1
A-Level Computer Science 9618 / Topic 16 / A2

Whose turn is it?

A single processor core can only run one instruction stream at a time, yet a computer appears to run dozens of programs at once. Learn how the OS maximises the use of resources, how the user interface hides the hardware, how processes move between the running, ready and blocked states, and how four scheduling routines and the interrupt-handling kernel decide what runs next.

The key idea

A process is a program that has been loaded into memory and is being executed. In multi-tasking the OS switches the processor between processes so quickly that they appear to run at the same time. Each process is running (on the processor), ready (waiting only for the processor) or blocked (waiting for an event such as I/O). The scheduler chooses the next ready process using a routine such as first come first served, shortest job first, shortest remaining time or round robin. The kernel acts as the interrupt handler: timer and I/O interrupts trigger the low-level scheduler to change which process runs.

The three process states and the transitions between them Ready Running Blocked scheduler dispatches it time slice ends / pre-empted waits for I/Oor an event I/O completes(interrupt) one running process per core; blocked never goes straight to running
Fig. 1: the running, ready and blocked states and the events that move a process between them
Section 01

Resources, the interface and processes.

At A Level you need to explain HOW the OS gets the most out of the hardware, not just list what it manages.

TransitionWhy it happens
ready → runningthe low-level scheduler selects the process and gives it the processor
running → readyits time slice ends (timer interrupt) or a higher-priority process pre-empts it
running → blockedit requests I/O or must wait for a resource or event, so it cannot continue
blocked → readythe I/O finishes or the event happens (signalled by an interrupt)
Examiner trap

A blocked process never goes straight to running. When its I/O completes it joins the ready queue and waits to be scheduled like everyone else.

Section 02

Four scheduling routines.

Scheduling is needed because there are more processes than processor cores. The scheduler must keep the CPU busy, give every process a fair share, give interactive users a quick response and make sure no process waits for ever (starvation). The four routines in the syllabus balance these aims differently.

RoutineHow it choosesPre-emptive?Benefit / drawback
First come first served (FCFS)in order of arrival (a FIFO queue)nosimple and fair in order; a long job makes every short job behind it wait
Shortest job first (SJF)the ready process with the shortest total burst time runs to completionnolowest average waiting time when all jobs are known; burst times must be estimated; long jobs can starve
Shortest remaining time (SRT)the process with the least time left; a newly arrived shorter job pre-empts the running oneyesshort jobs finish very quickly; more context switches; long jobs can starve
Round robin (RR)each process in turn gets a fixed time slice (quantum), then goes to the back of the ready queueyes (timer)fair and responsive, no starvation; frequent context switches add overhead; a poor quantum hurts performance
Worked example Four jobs, three routines
Jobs A, B, C and D all arrive at time 0 in that order, needing 6, 2, 8 and 3 ms of processor time. Find the order of execution and the average waiting time for FCFS, SJF and round robin with a 4 ms time slice.
  1. Waiting time = finish time − arrival time − burst time.
  2. FCFS: A 0-6, B 6-8, C 8-16, D 16-19. Waits: A 0, B 6, C 8, D 16. Average = 30 / 4 = 7.5 ms.
  3. SJF: shortest first, so B 0-2, D 2-5, A 5-11, C 11-19. Waits: B 0, D 2, A 5, C 11. Average = 18 / 4 = 4.5 ms.
  4. Round robin, 4 ms slice: A 0-4 (2 left), B 4-6 (done), C 6-10 (4 left), D 10-13 (done), A 13-15 (done), C 15-19 (done).
  5. RR waits: A 15 − 6 = 9, B 6 − 2 = 4, C 19 − 8 = 11, D 13 − 3 = 10. Average = 34 / 4 = 8.5 ms.
Answer: FCFS 7.5 ms, SJF 4.5 ms, RR 8.5 ms. SJF minimises the average wait; RR gives every job a turn early (all four have started by 10 ms) at the cost of a higher average.
Worked example Shortest remaining time with arrivals
P1 arrives at 0 needing 8 ms, P2 at 1 needing 4 ms, P3 at 2 needing 9 ms and P4 at 3 needing 5 ms. Schedule them with SRT and find the average waiting time.
  1. t = 0: only P1, so it runs.
  2. t = 1: P2 arrives with 4 ms; P1 has 7 ms left. 4 < 7, so P2 pre-empts P1. P2 runs 1-5 (P3 and P4 arrive with 9 and 5, both longer than P2's remaining time).
  3. t = 5: remaining times P1 7, P3 9, P4 5. P4 runs 5-10.
  4. t = 10: P1 (7) runs 10-17, then P3 runs 17-26.
  5. Waits: P1 17 − 0 − 8 = 9, P2 5 − 1 − 4 = 0, P3 26 − 2 − 9 = 15, P4 10 − 3 − 5 = 2. Average = 26 / 4 = 6.5 ms.
Answer: P1 0-1, P2 1-5, P4 5-10, P1 10-17, P3 17-26; average wait 6.5 ms (FCFS on the same jobs gives 8.75 ms).
Examiner trap

SJF is non-pre-emptive: once a job starts it runs to the end. If a question lets a newly arrived short job interrupt the running one, it is describing SRT.

Stage 1 · Learn

Check what the sim just showed you

Four quick checks. Each correct answer earns XP and records this skill on your profile.

Quick check+10 XP

Which state is a process in when it is waiting only for the processor?

Quick check+10 XP

Which routine runs the ready job with the shortest total time, without pre-emption?

Quick check+10 XP

In the lab, what does the processor do before running an interrupt service routine?

Quick check+10 XP

What moves a process from blocked to ready?

Section 03

The kernel as interrupt handler.

Scheduling decisions are triggered by interrupts. In the lab, fire interrupts of different priorities and watch the processor save its state, run the interrupt service routine and then resume: this is exactly the mechanism the kernel uses for low-level scheduling.

Your turn
Explain why round robin scheduling depends on interrupts.
Stage 2 · Exam

Exam-style questions

Unlocks once the four checks above are done. Worth more XP, written to A Level Paper 3 and Paper 4 standard.

Finish the four checks above to unlock the exam questions
Exam style+20 XP

Jobs needing 5, 1 and 3 ms arrive together. What is the average waiting time under SJF?

Exam style+20 XP

Which scheduling routine cannot cause starvation?

Exam style+20 XP

What causes a running process to move to the ready state under round robin?

Exam style+20 XP

Which describes how a user interface hides hardware complexity?

Skill unlocked

Process states and scheduling, dispatched.

This skill is now recorded on your profile. Keep the chain going.

-Rank -Level -Score -Topics
Go deeper · practice
Six original Cambridge-style questions
Maximising resources, hiding the hardware, process states, FCFS, SJF, SRT and round robin, and the kernel as interrupt handler.