Interrupts & Scheduling (OCR A-Level CS 1.2.1)

Sequence showing how the CPU handles an interrupt: finish the current instruction, save state to the stack, run the interrupt service routine, then restore state and resume.


Free Interrupts Scheduling revision resources (OCR A-Level Computer Science, 1.2.1)

We’ve made exam-style practice for this exact topic, free to download: Interrupts Scheduling question sheet, mark scheme and cheat sheet. Grab them, have a go, then read the full guide below.

How does one processor keep your music, browser, downloads and typing all running at once, and still react instantly when you press a key? Through interrupts and scheduling. Spec point 1.2.1 covers what an interrupt is, how the OS handles it, and the scheduling algorithms that share the CPU between processes — both common Paper 1 topics, including "explain how the OS deals with an interrupt" and "match each scheduling algorithm to its description".

This guide explains interrupts and the interrupt service routine, then the five scheduling algorithms you must know.

What is an interrupt?

An interrupt is a signal sent to the CPU that requests its attention. It can come from hardware (a device, for example "printer out of paper" or an I/O operation finishing), from software (a program error or a request for an OS service), or from the internal clock/timer that signals it is another process's turn. Because the CPU can be interrupted, multi-tasking is possible.

How does the operating system handle an interrupt?

When an interrupt arrives, the OS runs an interrupt service routine (ISR) — the code that deals with that specific interrupt. The steps are:

  1. The CPU finishes the current fetch-decode-execute cycle (the instruction in progress).

  2. It checks for interrupts and, if one has higher priority than the current task, it saves the contents of the registers and the program counter (the current state) onto the stack.

  3. It loads the address of the correct ISR (often via an interrupt vector) and runs it.

  4. When the ISR finishes, the saved state is restored from the stack and the interrupted program resumes where it left off.

Interrupts have priorities, so a more urgent interrupt can itself interrupt a lower-priority ISR; lower-priority interrupts wait their turn.

Why is scheduling needed?

A single CPU can run only one process at a time, but many processes want it. Scheduling is the OS deciding which process gets the CPU and for how long. A good scheduler aims to maximise throughput, be fair to all users, give acceptable response times, and keep hardware resources busy.

What are the main scheduling algorithms?

Round robin gives each process a fixed time slice (quantum) in turn, on a first-in-first-out basis. If a process does not finish in its slice, it goes to the back of the queue. A timer interrupt enforces the slices. This guarantees every process a fair, regular share, so it gives good response times for interactive users.

First come first served (FCFS) runs jobs in the order they arrive, with no priorities. It is simple but a long job at the front makes everything behind it wait, so it can be inefficient and unfair for interactive use.

Shortest job first (SJF) runs the process with the smallest estimated total run time next. Short jobs finish quickly, but it needs an estimate of each job's length, and long jobs may be starved.

Shortest remaining time (SRT) runs the process with the smallest estimated time left next, and can pre-empt a running job if a shorter one arrives. It reduces the number of waiting jobs but, again, needs time estimates.

Multi-level feedback queues use several queues with different priorities. Jobs move between queues based on how much CPU time they use, giving preference to short and I/O-bound jobs and keeping devices busy. It is the most flexible but the most complex.

Worked example

Three processes A, B and C arrive together with a round-robin quantum of 2 ms. The CPU runs A for 2 ms, then B for 2 ms, then C for 2 ms, then back to A, and so on. None waits longer than two slices for a turn, so a user typing in A feels an instant response even while B and C are still running — the strength of round robin.

Common exam mistakes

  • Saying an interrupt "stops the computer". It pauses the current process; the OS saves its state, services the interrupt, then resumes it.

  • Forgetting the state is saved (and where). Registers and the PC are pushed onto the stack so the process can resume exactly where it stopped.

  • Confusing SJF and SRT. SJF looks at the total estimated time; SRT looks at the remaining time and can pre-empt.

  • Describing round robin without the time slice. The fixed quantum enforced by a timer interrupt is the whole point.

  • Saying FCFS is "fair". It is simple but a long job blocks everything behind it, giving poor response times.

Quick recap

  • An interrupt is a signal to the CPU from hardware, software or the timer; it makes multi-tasking possible.

  • To handle it: finish the current instruction, save state (registers + PC) to the stack, run the ISR, restore state, resume. Interrupts have priorities.

  • Scheduling shares the CPU to maximise throughput, fairness, response time and resource use.

  • Round robin = fixed time slices; FCFS = arrival order; SJF = shortest total time; SRT = shortest time remaining (pre-emptive); MLFQ = priority queues, jobs move between them.

Frequently asked questions

What is an interrupt? An interrupt is a signal sent to the CPU requesting its attention. It can come from hardware (such as a device finishing an I/O task), from software (such as an error or a request for an OS service), or from the internal timer signalling another process's turn.

What is an interrupt service routine (ISR)? An ISR is the routine the operating system runs to deal with a particular interrupt. The CPU saves the current process's state to the stack, runs the ISR, then restores the state so the interrupted process can continue.

Why is processor scheduling needed? A single CPU can run only one process at a time, but many processes need it. Scheduling decides which process gets the CPU and for how long, so the system maximises throughput, stays fair, gives good response times and keeps hardware busy.

What is round robin scheduling? Round robin gives each process a fixed time slice (quantum) in turn. If a process does not finish in its slice it goes to the back of the queue. This guarantees every process a regular share and good response times for interactive users.

What is the difference between shortest job first and shortest remaining time? Shortest job first chooses the process with the smallest estimated total running time. Shortest remaining time chooses the process with the smallest estimated time left and can pre-empt a running process if a shorter one arrives.

Why might first come first served be inefficient? Because jobs run strictly in arrival order with no priorities, a long job at the front of the queue makes all the jobs behind it wait. This gives poor response times, especially for short or interactive tasks.

 

 

 

Logo

All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, trademarks and brands does not imply endorsement.


Follow us on:

Icon
Icon
Icon
Icon
Icon

Support@shuttlelearning.com

Logo

All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, trademarks and brands does not imply endorsement.


Follow us on:

Icon
Icon
Icon
Icon
Icon

Support@shuttlelearning.com

Logo

All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, trademarks and brands does not imply endorsement.


Follow us on:

Icon
Icon
Icon
Icon
Icon

Support@shuttlelearning.com