Menu

Process Management

Interrupts

An interrupt is a signal sent to the CPU to show that an event needs immediate attention. The CPU suspends whatever it is doing, runs the instructions that deal with the event, and then carries on. The set of instructions that handles the event is called the interrupt handler.

Interrupts are needed because a CPU works on one thing at a time. Without them, a key you pressed might not be read until the current process had finished, so typing would feel frozen and a device would seem to be ignored.

Hardware and software interrupts

TypeWhere it comes fromExample
Hardware interruptA hardware deviceA mouse button being clicked, or a timer chip signalling that a time slice has ended
Software interruptA programA drawing app asking the operating system to load a picture from storage

Programs do not access hardware devices or storage directly, so they raise a software interrupt to ask the operating system to do it for them. Most software interrupts are ordinary requests like this, not faults.

What happens when one arrives

Imagine you are typing a story into a word processor and you press the letter h. Pressing the key is an event that cannot wait, so the keyboard raises a hardware interrupt. The CPU finishes the instruction it is on, the operating system notes which process was running and where it had reached, and the keyboard interrupt handler runs. The key press is read and passed to the word processor, which adds h to the text, and the process then resumes exactly where it left off, so you never notice the pause.

A flowchart: the word processor runs, pressing h raises a hardware interrupt, the CPU finishes its instruction, the OS notes where the process had reached, the keyboard interrupt handler runs, and the process resumes.

The operating system manages interrupts as part of process management. It decides which interrupt is dealt with first when two arrive together, makes sure the right process is resumed afterwards, and keeps a flood of interrupts from pushing ordinary processes aside for too long.

Practise this