Learning Objectives
- Define an interrupt and explain why interrupts are used.
- Distinguish between hardware interrupts and software interrupts.
- Describe how an interrupt is generated and handled.
- Explain the role of an interrupt service routine.
- Describe what happens to the interrupted process before and after servicing the interrupt.
Key Terms
- Interrupt
- A signal or event that requests the processor’s immediate attention.
- Hardware interrupt
- An interrupt generated by a hardware event, such as a key press or mouse movement.
- Software interrupt
- An interrupt generated by a program or exceptional software condition, such as division by zero.
- Interrupt service routine (ISR)
- A specialised routine executed to handle a particular interrupt.
- Processor state
- Information needed to continue a process correctly, including register contents and execution position.
- Context
- The stored state of a process at a particular moment.
- Exception
- An unusual condition detected while executing software, such as an invalid arithmetic operation.
- Resume
- Continue execution of the interrupted process after the interrupt has been handled.
- Priority
- The relative importance used to decide which interrupt should be handled first.

Purpose Of Interrupts
An interrupt is a signal or event that requests the processor’s attention. Interrupts allow the processor to respond to events when they occur instead of repeatedly checking every device or condition. This helps the system use processor time efficiently and remain responsive.
For example, a processor does not need to spend all its time asking whether a key has been pressed. When a key press occurs, keyboard hardware generates an interrupt. The operating system can then run the appropriate routine to collect and process the input.
Interrupt handling is an operating-system responsibility because the OS coordinates processes and hardware. The OS must pause normal execution safely, identify the event, run the correct service routine and then decide what should happen next.
Hardware And Software Interrupts
Hardware interrupts are produced by hardware events. Cambridge examples include pressing a key on the keyboard and moving the mouse. Other hardware events can include completion of a device operation, but answers should stay close to the event described in the question.
Software interrupts are produced by software conditions or program requests. Cambridge examples include division by zero and two processes trying to access the same memory location. These conditions require controlled handling because continuing the current instruction sequence without intervention may be impossible or unsafe.
The distinction is based on the source of the event. A physical input or device event is hardware-generated. An invalid program operation or conflict detected while software runs is software-generated.
How An Interrupt Is Handled
When an interrupt is generated, the processor completes the current instruction or reaches a safe point. The current process must be paused. Information needed to continue it, such as relevant register contents and the position of the next instruction, is saved.
The processor or operating system identifies the interrupt and transfers control to the appropriate interrupt service routine. The ISR contains the instructions needed to handle that event. A keyboard ISR may read the key code, while a division-by-zero handler may stop the affected process or report an error.
When the service routine finishes, the saved state can be restored and the interrupted process can resume. In some cases, the result of the interrupt changes what happens: a faulty process may be terminated, a waiting process may be made ready, or input data may be delivered to an application.
The Result Of Interrupt Handling
The result depends on the event. A mouse-movement interrupt may update pointer data and allow the user interface to redraw the pointer. A keyboard interrupt may place an input code in a buffer and notify the active application. A software fault may produce an error message and prevent the invalid operation from continuing.
An interrupt does not necessarily mean the whole computer stops. The operating system handles the event in a controlled way and then continues other work. The interruption may be extremely brief and invisible to the user.
For full marks, describe the sequence: interrupt generated; current process state saved; correct ISR selected and executed; event handled; state restored or another action selected; processing resumes. If the question names a specific event, adapt the result to that event.
Examples Of Interrupts
| Event | Type | Possible Handling Result |
|---|---|---|
| Keyboard key pressed | Hardware interrupt | ISR reads the key code and supplies it to the operating system or active application. |
| Mouse moved | Hardware interrupt | ISR records movement data and the interface updates the pointer. |
| Division by zero | Software interrupt | The invalid operation is stopped and an error is reported or the process is terminated. |
| Two processes attempt the same protected memory location | Software interrupt | The OS prevents unsafe access and handles the conflict. |
Interrupt-Handling Sequence
| Step | Action |
|---|---|
| 1 | An event generates an interrupt. |
| 2 | The processor reaches a safe point and pauses the current process. |
| 3 | The process state is saved. |
| 4 | The appropriate interrupt service routine is selected and executed. |
| 5 | The event is handled and any result is recorded. |
| 6 | The saved state is restored or another scheduling decision is made. |
| 7 | Processing resumes. |
Worked Examples
Keyboard Interrupt
Question: Describe what happens after a user presses a key while a word processor is running.
- The keyboard hardware generates an interrupt.
- The processor pauses the current process at a safe point and its state is saved.
- Control passes to the keyboard interrupt service routine.
- The ISR reads the key code and passes or stores the input for the operating system.
- The word processor receives the input, and the saved process can resume.
Answer: The key press is handled by a hardware interrupt and a keyboard ISR without the processor constantly checking the keyboard.
Division By Zero
Question: A program attempts to divide a value by zero. Explain how an interrupt can be used.
- The invalid software condition generates a software interrupt or exception.
- The current process is paused and its state is available to the operating system.
- A suitable ISR or exception handler runs.
- The invalid operation is prevented, and the system reports an error or terminates the affected process.
Answer: A software interrupt transfers control to an error-handling routine so the invalid division is handled safely.
Examination Guidance
- Always identify whether the source is hardware or software when the question provides an event.
- Use the full term interrupt service routine before using the abbreviation ISR.
- Mention saving and restoring process state to explain how execution can continue correctly.
- Describe what the ISR does for the named event, not just that it “handles it”.
- Do not say that the processor permanently abandons every interrupted process.
Common Mistakes
- Calling every interrupt a hardware fault.
- Saying the interrupt service routine generates the interrupt rather than handles it.
- Forgetting to save the current process state.
- Claiming the processor continues the current program while simultaneously executing the ISR on the same core.
- Using keyboard input as a software interrupt example.
Knowledge Check
1. What is an interrupt?
2. Give one hardware-interrupt example.
3. Give one software-interrupt example.
4. What is an interrupt service routine?
5. Why is process state saved?