An interrupt is like a signal that tells the CPU to immediately stop what it's doing and handle something more urgent. It is literally an interruption to the CPU execution flow.
Suppose you're working on your laptop and you get a notification saying your battery is low. You stop whatever you were doing and plug the device in. That's an interrupt — you received an interrupt and handled it.
Without interrupts, the CPU would have to constantly check ("poll") various devices to see if they need servicing. It would also have no clean, safe way to handle exceptions.
The core contract
When an interrupt fires, the CPU:
- Saves its current state (registers, flags, program counter) onto the stack.
- Jumps to a pre-registered handler function — the ISR, or Interrupt Service Routine.
- Executes the handler.
- Restores the saved state and continues exactly where it left off.
Note: interrupts are not the only mechanism to handle exceptions in modern kernels — a more general interrupt mechanism is used via task gates, which are part of the x86 legacy task switching.
Types of interrupts
| Type | Source | Example |
|---|---|---|
| Synchronous | Hardware | Keyboard, timer, NIC |
| Asynchronous | Software | INT instruction, syscalls |
| Synchronous exception | CPU error | Page fault, division by zero |
| Synchronous trap | Deliberate | INT 3 (breakpoint) |
Asynchronous hardware interrupts are requested by the chipset via Interrupt Request Lines (IRQs).
Software interrupts are triggered by the INT n instruction. On Linux x86, int 0x80 triggers the kernel; the system call number is in eax. The kernel handles it and returns via iret.
Ring transition
Software interrupts are the gateway between user mode (Ring 3) and kernel mode (Ring 0). The CPU checks privilege levels during the interrupt. Modern x86 uses SYSCALL/SYSRET instead of INT 0x80.
How the CPU locates the ISR
The CPU uses the interrupt vector number to index the IDT — the Interrupt Descriptor Table. On x86 it's an array of 256 entries, each 8 bytes; on x86_64, 16 bytes. The base address is stored in IDTR (loaded with LIDT). For interrupt 0: handler = IDTR + 0 * offset.
If no handler exists for an asserted interrupt, the CPU escalates to interrupt 13 (General Protection Fault); if that's missing, to interrupt 8 (Double Fault); and finally to a Triple Fault (CPU reset).
The IDT entry structure (x86)
Bits 15–0: offset low bits. Bits 31–16: segment selector. Bit 47: present (P). Bits 46–45: DPL. Bits 43–40: gate type.
Modern x86 modes push additional fields, but the essentials are:
P: valid descriptorDPL: privilege level that can assert the interrupt viaINTG: offset is scaled by 4K/64K
Higher-level languages
Higher-level languages abstract interrupts away. The pattern everywhere is: register a callback → wait → handle → resume.
- JavaScript's event loop is essentially a software interrupt controller:
setTimeout,addEventListener,fetchall "register interrupt handlers" that fire asynchronously. - Python's
signalmodule provides direct access to Unix signals. - Java's
Thread.interrupt()is the same idea.
Wrapping up
Interrupts are the fundamental mechanism that makes computing responsive and efficient. Keyboards feel instant, devices respond without clogging the CPU, and the OS can multitask. Understanding interrupts is essential for kernel development and embedded systems — but even debugging high-level performance issues benefits from the picture.