What Are Interrupts?
You'll learn: how the CPU receives asynchronous notifications about events that need immediate attention.
The Core Idea
An interrupt is a signal that temporarily stops the CPU from whatever it's currently executing so it can handle something urgent. Think of it like a phone call interrupting your work—you pause what you're doing, deal with the call, then return to your task.
Interrupts allow hardware devices and software to notify the CPU of events asynchronously—meaning they can happen at any unpredictable moment, not just when the CPU is expecting them.
Two Types of Interrupts
Hardware Interrupts
These come from physical devices outside the CPU:
- Your keyboard sends an interrupt when you press a key
- A network card signals when data arrives
- A disk drive interrupts when it finishes reading data
- A timer chip interrupts at regular intervals
Software Interrupts
These are triggered by executing programs:
- When a program makes a system call (which you just learned about!), it often triggers a software interrupt to switch from user mode to kernel mode
- Programs can deliberately trigger interrupts to request OS services
- Exceptions (like division by zero) also generate interrupts
How It Works
When an interrupt occurs, the CPU:
- Saves its current state (what instruction it was on, register values)
- Jumps to special interrupt-handling code in the OS kernel
- Executes the interrupt handler (also called interrupt service routine)
- Restores the saved state and resumes the interrupted task
This mechanism is crucial because it lets the OS respond immediately to events without constantly checking ("polling") every device to see if something happened.
Key Takeaway: Interrupts are asynchronous signals—from hardware or software—that temporarily halt the CPU to handle urgent events, enabling responsive multitasking and efficient I/O management.