🔒 Pro · Component 1 · 1.2 Software and Software Development
1.2.1c Interrupts and Scheduling Algorithms
OCR H446 · A Level Computer Science · ~12 min read
Notes
—
Video
—
Slides
—
Worksheet
—
Quiz
Interrupts
An interrupt is a signal sent to the CPU by hardware or software to indicate that an event requires immediate attention. Interrupts allow the CPU to respond to events asynchronously without constantly polling (checking) devices.
Types of interrupt:
Hardware interrupt: generated by a hardware device (e.g. keyboard keypress, mouse click, disk I/O completion, timer).
Software interrupt: generated by a running program requesting an OS service (system call / trap instruction). E.g. a program requesting file I/O.
Timer interrupt: generated by the system timer at regular intervals; used by the OS scheduler to preempt processes (enforce time quanta in round-robin).
Exception/fault: generated by an error condition (divide by zero, illegal memory access, overflow). Can be seen as a software interrupt.
Interrupt handling (Interrupt Service Routine — ISR):
An interrupt signal is received.
The CPU completes the current instruction (it does not stop mid-instruction).
The CPU saves the state of the current process (program counter, registers) to the stack/PCB.
The CPU disables (masks) further interrupts to avoid nested interrupts (in some systems).
The CPU consults the interrupt vector table (IVT) to find the address of the relevant ISR.
The ISR executes, handling the interrupt.
On completion, the saved state is restored and the original process resumes.
Interrupt priority:
Different interrupts have different priorities. Higher-priority interrupts (e.g. power failure, hardware error) can interrupt lower-priority ISRs. A priority system ensures critical events are handled first.
CPU Scheduling
The scheduler is the OS component that decides which ready process gets CPU time next. Scheduling aims to maximise CPU utilisation, throughput, and fairness while minimising response time and waiting time.
Scheduling criteria:
CPU utilisation: keep the CPU as busy as possible.
Throughput: number of processes completed per unit time.
Turnaround time: total time from process submission to completion.
Waiting time: total time spent in the ready queue.
Response time: time from submission to first response (important for interactive systems).
Types of scheduling:
Preemptive: the OS can forcibly remove the CPU from a running process (e.g. when its time quantum expires or a higher-priority process becomes ready).
Non-preemptive: a process runs until it voluntarily yields the CPU (blocks for I/O or terminates). Simpler but can cause poor response time.
Scheduling Algorithms
1. First-Come, First-Served (FCFS)
Processes are scheduled in the order they arrive in the ready queue. Simple but can cause the convoy effect: a long process at the front of the queue delays all shorter processes behind it, increasing average waiting time. Non-preemptive.
2. Shortest Job First (SJF) / Shortest Job Next (SJN)
The process with the shortest estimated CPU burst is scheduled next. Minimises average waiting time and is optimal for minimising average turnaround time. Problems: requires knowing burst time in advance (difficult in practice); can cause starvation of long processes if short processes keep arriving.
Non-preemptive SJF: current process runs to completion before next is selected.
Preemptive SJF (Shortest Remaining Time First, SRTF): if a new process arrives with a shorter burst than the remaining time of the current process, the current process is preempted.
3. Round-Robin (RR)
Each process is given a fixed time quantum (time slice, e.g. 10–100 ms). After its quantum expires, the process is preempted and placed at the back of the ready queue. Designed for time-sharing systems; fair; good response time. Performance depends heavily on the size of the time quantum:
Too large: degenerates towards FCFS.
Too small: excessive context switching overhead reduces CPU efficiency.
4. Shortest Remaining Time First (SRTF)
Preemptive version of SJF. The process with the shortest remaining burst time always runs. Optimal for minimising average waiting time but causes starvation and requires estimating remaining burst times.
5. Priority Scheduling
Each process is assigned a priority. The highest-priority ready process is scheduled next. Can be preemptive or non-preemptive. Problem: starvation — low-priority processes may never run. Solution: ageing — gradually increase the priority of waiting processes over time.
6. Multi-level Feedback Queue (MLFQ)
Multiple queues with different priority levels. Processes start in the highest-priority queue. If a process uses its full time quantum (CPU-bound), it is demoted to a lower-priority queue. Interactive/I/O-bound processes that give up the CPU voluntarily are promoted or remain in higher queues. Combines the benefits of multiple algorithms. Used in modern OS kernels (Linux CFS, Windows scheduler).
Algorithm
Preemptive?
Starvation?
Key advantage
Key disadvantage
FCFS
No
No
Simple
Convoy effect; poor average wait time
SJF
No
Yes (long jobs)
Minimises avg. waiting time
Requires knowing burst time; starvation
SRTF
Yes
Yes (long jobs)
Optimal avg. waiting time
Starvation; burst time estimation needed
Round-Robin
Yes
No
Fair; good response time
Quantum size critical; context switch overhead
Priority
Both
Yes (low priority)
Important tasks run first
Starvation; solved by ageing
MLFQ
Yes
Low (ageing)
Combines benefits; adaptive
Complex to implement
Exam tip: For scheduling algorithm questions, be prepared to calculate waiting time and turnaround time given a set of processes with arrival/burst times. Know: turnaround time = completion time − arrival time; waiting time = turnaround time − burst time.
Exam tip: Starvation = a process never gets CPU time. Ageing = fix for priority starvation. Convoy effect = fix with SJF. Context switch overhead = fixed time quantum in RR that's too small.
⚠ Common Mistakes
Saying the CPU "stops immediately" when an interrupt arrives — it always completes the current instruction first.
Confusing SJF (non-preemptive) and SRTF (preemptive SJF).
Saying Round-Robin prevents starvation — yes it does; but a quantum too small causes excessive context switch overhead.
✓ Notes completed!
▶
Video coming soon
Click to advance · Arrow keys also work
Click slide or press arrow keys to navigate
✍
Worksheet — 1.2.1c Interrupts and Scheduling
8 questions · 20 marks · instantly marked
Q1Describe the sequence of events that occurs when a hardware interrupt is received by the CPU.[4 marks]
✓ Mark scheme
The CPU completes the current instruction [1]; saves the state of the current process (program counter, register values) to the stack or PCB [1]; uses the interrupt vector table to find the address of the relevant ISR [1]; executes the ISR to handle the interrupt; restores the saved state and resumes the original process [1].
Q2Distinguish between a hardware interrupt and a software interrupt (trap), giving one example of each.[4 marks]
✓ Mark scheme
Hardware interrupt: generated by a physical hardware device to signal that it requires CPU attention [1]; e.g. keyboard keypress, disk I/O completion, timer interrupt [1]; software interrupt (trap): generated by an executing program requesting an OS service (system call) or as the result of an error condition [1]; e.g. a program requesting file I/O, a divide-by-zero exception [1].
Q3Explain what the interrupt vector table (IVT) is and how it is used during interrupt handling.[2 marks]
✓ Mark scheme
The interrupt vector table is a table stored in memory that maps each interrupt number/type to the starting address (memory location) of its corresponding interrupt service routine (ISR) [1]; when an interrupt occurs, the CPU uses the interrupt number to index into the IVT and jumps to the address of the appropriate ISR to handle the interrupt [1].
Q4Three processes arrive at time 0 with burst times: P1=6ms, P2=2ms, P3=4ms. Calculate the average waiting time using: (a) FCFS, (b) SJF. Show your working.[4 marks]
Q5Explain what starvation is in CPU scheduling and describe how ageing resolves it.[3 marks]
✓ Mark scheme
Starvation occurs when a process is unable to get CPU time because other processes with higher priority (or shorter burst time) continually take precedence, potentially waiting indefinitely [1]; ageing is a technique that gradually increases the priority of a process the longer it has been waiting [1]; eventually, the process's priority becomes high enough to be scheduled, preventing indefinite starvation [1].
Q6Explain the convoy effect in FCFS scheduling and explain why SJF avoids this problem.[3 marks]
✓ Mark scheme
The convoy effect occurs in FCFS when a CPU-intensive (long) process is at the head of the ready queue, causing all shorter processes behind it to wait a long time, increasing average waiting time [1]; SJF avoids this by always selecting the process with the shortest estimated burst time next [1]; shorter processes skip ahead and are executed before longer ones, minimising the average waiting time across all processes [1].
Q7Explain how Round-Robin scheduling works and explain what happens if the time quantum is set too small.[3 marks]
✓ Mark scheme
Round-Robin gives each process a fixed time quantum (time slice); when a process's quantum expires it is preempted and placed at the back of the ready queue, and the next process gets the CPU [1]; this ensures all processes get CPU time fairly and prevents starvation [1]; if the time quantum is too small, the CPU spends a disproportionate amount of time context switching between processes rather than executing them, reducing effective CPU utilisation [1].
Q8Describe how a multi-level feedback queue (MLFQ) scheduling algorithm works and give one advantage over a simple Round-Robin scheduler.[2 marks]
✓ Mark scheme
MLFQ uses multiple queues with different priority levels; processes start in the highest-priority queue and are demoted to lower-priority queues if they use their full time quantum (CPU-bound behaviour), while I/O-bound processes that frequently yield remain in or are promoted to higher-priority queues [1]; advantage: MLFQ adapts to process behaviour, giving I/O-bound/interactive processes faster response while still executing CPU-bound tasks, unlike plain Round-Robin which treats all processes identically [1].
Topic Quiz
1 of 15
You scored
out of 15
🎯
Mini Test — 1.2.1c Interrupts & Scheduling
10 questions · 10 marks · 10 minutes
5 MCQ + 5 short answer
⏱10:00
10 marks
Section A — Multiple Choice
Q1When a hardware interrupt is received, what does the CPU do first?
Q2Which scheduling algorithm assigns each process an equal fixed time slice?
Q3Which scheduling algorithm can cause the 'convoy effect'?
Q4Ageing is a solution to:
Q5SRTF (Shortest Remaining Time First) is a preemptive version of which algorithm?
Section B — Short Answer
Q6What is an Interrupt Service Routine (ISR)?
Mark schemeA routine (section of code) that is executed by the CPU in response to a specific interrupt signal, handling the event that caused the interrupt. [1 mark]
Q7What is the purpose of the interrupt vector table?
Mark schemeIt maps each interrupt type/number to the memory address of its corresponding ISR, so the CPU knows where to jump to handle each interrupt. [1 mark]
Q8State one disadvantage of SJF scheduling.
Mark schemeRequires knowing the burst time of processes in advance (difficult/impossible in practice) [1] / can cause starvation of long processes [1].
Q9Define turnaround time.
Mark schemeTurnaround time is the total time from when a process arrives (is submitted) to when it completes execution. [1 mark]
Q10What happens in Round-Robin if the time quantum is set too large?
Mark schemeIf the time quantum is too large, Round-Robin degenerates towards FCFS because processes will typically complete within their quantum rather than being preempted. [1 mark]