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.
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.
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.
Maximising the processor: while one process waits for slow I/O, the OS blocks it and gives the processor to another process, so the CPU is kept busy (multi-tasking). Scheduling aims for high throughput and fair response times.
Maximising memory: memory is allocated and freed dynamically, shared code (e.g. DLLs) is loaded once, and virtual memory lets more processes be held than would fit in RAM.
Maximising I/O and storage: buffers, spooling and Direct Memory Access (DMA) let devices transfer data while the processor does other work; the device sends an interrupt when the transfer is finished.
Hiding the hardware: the user interface (GUI or command line) and the OS's system calls (APIs) let users and programs say what they want (save this file, print this page) without knowing how the hardware does it: no sector numbers, device registers or memory addresses. Device drivers hide the differences between devices.
Transition
Why it happens
ready → running
the low-level scheduler selects the process and gives it the processor
running → ready
its time slice ends (timer interrupt) or a higher-priority process pre-empts it
running → blocked
it requests I/O or must wait for a resource or event, so it cannot continue
blocked → ready
the 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.
Routine
How it chooses
Pre-emptive?
Benefit / drawback
First come first served (FCFS)
in order of arrival (a FIFO queue)
no
simple 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 completion
no
lowest 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 one
yes
short 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 queue
yes (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.
Waiting time = finish time − arrival time − burst time.
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.
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.
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).
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.
t = 0: only P1, so it runs.
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).
t = 5: remaining times P1 7, P3 9, P4 5. P4 runs 5-10.
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.
The kernel is the core of the OS that stays in memory. It handles every interrupt: at the end of each fetch-execute cycle the processor checks for interrupts and, if one is waiting with a high enough priority, passes control to the kernel's interrupt service routine.
Timer interrupt: a hardware timer interrupts at the end of each time slice. The kernel saves the running process's context (registers, program counter, state) in its process control block (PCB), moves it to ready, and the low-level scheduler dispatches the next ready process by loading its saved context. This is a context switch.
I/O interrupt: when a device finishes a transfer it interrupts; the kernel moves the process that was waiting for it from blocked to ready.
High-level vs low-level scheduling: the high-level (long-term) scheduler decides which programs are loaded into memory as processes; the low-level (short-term) scheduler decides which ready process gets the processor next.
Your turn
Explain why round robin scheduling depends on interrupts.
Round robin is pre-emptive: a process must be stopped when its time slice ends even if it has not finished. A timer interrupt passes control to the kernel, which saves the process's context, puts it at the back of the ready queue and dispatches the next process.
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.