SLIDE 1 / 11
CSZone.co.uk
OCR H446 · Component 1 · 1.2.1

Interrupts and
Scheduling Algorithms

OCR A Level Computer Science · cszone.co.uk
H446 SpecA Level
Learning Objectives

By the end of this topic you will be able to:

Describe the role of interrupts and the interrupt handling process
Explain interrupt priorities and vectored interrupts
Compare scheduling algorithms: FCFS, Round Robin, SJF, Priority scheduling
Explain starvation and how aging resolves it
Interrupts

What is an Interrupt?

An interrupt is a signal sent to the CPU indicating that a device or process requires immediate attention. The CPU checks for pending interrupts at the end of each execute stage.
Types of Interrupt
Hardware: keyboard press, mouse click, disk I/O complete
Software: division by zero, illegal memory access
Timer: OS timer fires to allow CPU scheduling
Interrupt Handling
1. CPU checks interrupt flag at end of execute.
2. If interrupt: context saved to stack (all registers).
3. PC ← ISR address (from interrupt vector table).
4. ISR executes.
5. Context restored; original program resumes.
Interrupt Priority

Interrupt Priority and Vectored Interrupts

Priority: each interrupt has a priority level. If a lower-priority interrupt is being handled by an ISR, a higher-priority interrupt can interrupt the ISR itself (nested interrupts).
Interrupt vector table: a table in memory mapping each interrupt type to the starting address of its ISR. The CPU uses this table to jump to the correct ISR immediately.
Vectored interrupts: each interrupt type has its own dedicated vector (ISR address), allowing the CPU to jump directly to the correct handler without software checking which interrupt occurred.
Scheduling

CPU Scheduling Algorithms

The scheduler decides which ready process runs next. Goals: maximise CPU utilisation, minimise wait time, ensure fairness, meet deadlines.
AlgorithmDescriptionIssue
FCFSFirst Come First Served — runs in arrival orderConvoy effect (long jobs block short ones)
Round RobinEach process gets a time quantum; preempted if not doneOverhead from frequent context switches if quantum too small
SJFShortest Job First — runs shortest estimated job nextStarvation of long jobs; requires burst time estimation
PriorityHighest priority runs first; same priority = FCFSStarvation of low-priority processes
Starvation and Aging

Starvation and Aging

Starvation: a process is indefinitely delayed because higher-priority processes keep being scheduled before it. Can occur with SJF (long jobs wait forever if short jobs keep arriving) or priority scheduling (low-priority jobs never run).
Aging: a solution to starvation. The priority of a waiting process is gradually increased over time. Eventually, even a low-priority process gets high enough priority to run. Used in priority scheduling and SJF.
Round Robin is inherently fair (every process gets equal time slices) and does not suffer from starvation — but it can be inefficient for I/O-bound or very short processes.
Exam Practice
OCR H446 Style · 4 marks
Compare Round Robin and Shortest Job First (SJF) scheduling. For each, state one advantage and one disadvantage.
[4 marks]
2
Round Robin: Advantage: fair — every process gets CPU time, no starvation [1]. Disadvantage: overhead from frequent context switching; if quantum is too small, CPU spends more time switching than executing [1].
2
SJF: Advantage: minimises average waiting time by completing short jobs quickly [1]. Disadvantage: starvation — long jobs may never run if short jobs keep arriving; also requires knowing burst time in advance [1].
Common Mistakes

Don’t Lose Marks

!
Saying the CPU handles interrupts immediately when they occur — the CPU only checks for interrupts at the end of the execute stage, not continuously during an instruction.
!
Confusing context switch with interrupt handling. Context switching saves/restores a process state for scheduling. Interrupt handling saves state to handle a device event. Both save registers, but for different reasons.
!
Saying Round Robin never has any disadvantages — it has overhead from frequent context switches. If the time quantum is too small (e.g. 1ms), the CPU can spend more time switching than doing useful work.
1.2.1c Complete
Well done! ✓
Interrupts and Scheduling Algorithms
Return to lesson to continue