Operating systems: scheduling, memory and interrupts

A-Level Computer Science · Operating Systems, Networks and AI

What the operating system actually manages

Processes, memory, files, devices, security and the interface. All of it exists to share limited hardware between competing demands while hiding the detail from applications.

Process states

A process is running (using the processor), ready (able to run, waiting its turn) or blocked (waiting for input, output or a resource). A blocked process cannot go straight to running — it must return to ready first, and that transition is a standard exam point.

Scheduling algorithms

Round robin gives each process a fixed time slice in turn: fair, and prevents any process monopolising the CPU, but ignores urgency. First come first served is simple but a long job blocks everything behind it. Shortest job first minimises average waiting time but can starve long jobs indefinitely. Priority scheduling serves important work first, and needs ageing — gradually raising the priority of waiting processes — to stop low-priority work being starved.

Memory management

Paging divides memory into fixed-size pages; segmentation divides it into variable-size logical units. Virtual memory uses disk as an extension of RAM, swapping out pages that are not currently needed. It allows programs larger than physical memory to run, at the cost of disk access time — and if too much swapping occurs the system thrashes: the processor spends more time moving pages than executing instructions.

Interrupts and the OS

Interrupt handling is what makes a single processor appear to do many things at once. The processor checks for interrupts at the end of each cycle, saves the process state on the stack, runs the service routine, then restores and resumes — the same mechanism that underlies multitasking.

Bo nho ao — trang nao khong dung thi day ra diaRAM (nhanh, nho)trang 3 — dang chaytrang 7 — dang chaytrang 1 — vua dungtrang 9 — vua dungDIA (cham, lon)trang 2 — lau khong dungtrang 5trang 8trang 4day ranap vaoDoi trang qua nhieu = THRASHING: CPU ban ro nhung khong lam duoc viec gi
Virtual memory is a trade-off: it lets you run programs larger than RAM, but if too many pages are swapped the system is busy without making progress — that is thrashing.

Worked example: compare two scheduling algorithms on the same data

Four processes all arrive at time $0$ with run times: $P1=8$, $P2=3$, $P3=5$, $P4=2$ (in milliseconds).

Calculate the average waiting time under (a) first come first served, and (b) shortest job first. Comment.

Solution

(a) First come first served — order $P1, P2, P3, P4$.

$P1$ waits $0$
$P2$ waits $8$
$P3$ waits $8+3=11$
$P4$ waits $8+3+5=16$

Average waiting time $=\dfrac{0+8+11+16}{4}=\dfrac{35}{4}=\mathbf{8.75}$ ms.

(b) Shortest job first — order $P4, P2, P3, P1$.

$P4$ waits $0$
$P2$ waits $2$
$P3$ waits $2+3=5$
$P1$ waits $2+3+5=10$

Average waiting time $=\dfrac{0+2+5+10}{4}=\dfrac{17}{4}=\mathbf{4.25}$ ms.

Comment. Shortest job first cuts the average waiting time roughly in half. The intuitive reason: running short jobs first means fewer processes have to wait behind a long job.

But the cost must be stated. $P1$ — the longest process — waits the longest. In a real system new processes keep arriving, so if short jobs keep appearing, $P1$ may wait indefinitely. This phenomenon is called starvation, and it is why real operating systems rarely use pure shortest job first.

One more practical problem: this algorithm requires knowing each process's run time in advance, while an operating system can usually only estimate it from history. So real systems often use round robin with multiple priority levels and aging — both fair and starving no one.

Common mistake

Drawing a process state diagram with an arrow straight from 'blocked' to 'running'. When a blocked process is released it only returns to 'ready' and must wait for the scheduler to give it a turn. The mark scheme always checks this detail.

Key takeaway

The three process states and the valid transitions between them. Every scheduling algorithm has a cost: round robin ignores urgency, shortest job first causes starvation, priority needs aging. Virtual memory extends RAM but leads to thrashing if overdone.

← File handling, exceptions and the ethics of computing · All A-Level Computer Science lessons · Practice A-Level Computer Science questions (free, instant scoring) · Networks in depth: protocols, addressing and the cloud →