Interrupts and Buffers ⚡
Efficient computing relies on the Operating System's ability to multitask and manage the speed differences between the CPU and external devices.
Interrupts 🔔
An interrupt is a signal sent from a device or software to the CPU, requesting immediate attention.
Examples:
- Keyboard key press ⌨️
- Printer out of paper 🖨️
- Software error (e.g., divide by zero) ❌
- Timer interrupt ⏱️
Buffers 📦
A buffer is a temporary memory area used to hold data while it is being moved, compensating for speed differences between hardware.
Examples:
- Streaming video (prevents stuttering) 🎥
- Sending a document to a printer 📄
- Hard drive data transfer 💾
5b. Where Interrupts Come From
The syllabus expects the sources of interrupts by category, not just examples. There are four:
- Hardware interrupt — generated by a physical device. A key is pressed, a mouse is moved, a printer runs out of paper, a device is unplugged.
- Software interrupt — generated by a running program when something goes wrong or a service is needed. Division by zero, an attempt to access memory the program does not own, or a request for an operating system service.
- Timer (clock) interrupt — generated at fixed intervals by the system clock. This is what makes multitasking possible: it periodically takes the CPU away from the current process so the OS can give another one a turn.
- Input/output interrupt — generated when a device has finished a transfer or needs more data. A disk has completed a read; a printer buffer has emptied.
5c. Interrupt Priority
Interrupts do not all matter equally, so each is given a priority. If an interrupt arrives while another is already being serviced, the CPU compares the two:
- If the new interrupt is higher priority, the current service routine is itself suspended — its state is saved in the same way — and the more urgent one is handled first.
- If it is lower or equal priority, it waits in a queue until the current routine has finished.
This is why a power-failure warning or a hardware fault is dealt with immediately while a printer asking for more data waits its turn. Without priorities, a trivial but frequent interrupt could delay a critical one indefinitely.
6. How the OS Handles Interrupts 🛠️
When an interrupt occurs, the OS must ensure the current task is not lost. It follows these steps:
7. Buffers and Interrupts Working Together
Exam questions rarely ask about a buffer or an interrupt on its own. They describe printing, and expect you to explain how the two operate as one mechanism. Here is that sequence:
- The user sends a document to print. The CPU transfers the data into the printer buffer — quickly, because that is a memory-to-memory transfer.
- The CPU is now free and returns to other tasks. It does not wait for the printer, which is thousands of times slower than it is.
- The printer works through the buffer at its own speed, printing as it goes.
- When the buffer is nearly empty, the printer sends an interrupt to the CPU requesting more data.
- The CPU saves what it was doing, refills the buffer, and resumes the interrupted task.
- Steps 3 to 5 repeat until the whole document has been printed.