What Is an Interrupt?

An interrupt is a signal sent to the CPU that temporarily halts the current program execution so that another, more urgent task can be attended to.

Think of it like a fire alarm — no matter what you’re doing, you must stop and respond.

Once the interrupt is handled, the CPU returns to its previous task as if nothing happened.

1. Why Interrupts Exist

Interrupts allow computers to be:

  • Responsive to real-world events (e.g., mouse clicks, network packets)
  • Efficient by eliminating constant polling
  • Multitasking-capable, enabling asynchronous operations

Without interrupts, CPUs would need to constantly check for events — a wasteful process called polling.

2. Types of Interrupts

TypeTrigger SourceExamples
Hardware InterruptExternal devicesKeyboard input, mouse, disk I/O
Software InterruptCPU instructionsSystem calls, int in x86
Timer InterruptPeriodic timer signalsMultitasking, scheduling
Spurious InterruptElectrical noise or bugsUnexpected or unrecognized signals
Non-Maskable Interrupt (NMI)Critical hardware failurePower loss, memory parity errors

3. Interrupt Handling Overview

When an interrupt occurs:

  1. CPU pauses current execution
  2. It saves context (registers, program counter)
  3. Jumps to a specific interrupt handler
  4. Executes the handler routine
  5. Restores context and resumes execution

This is known as the Interrupt Handling Cycle.

4. Interrupt Vector Table

To manage multiple interrupt sources, systems use an Interrupt Vector Table (IVT):

  • A lookup table mapping interrupt numbers to handler addresses
  • Stored in memory at a well-known location (e.g., 0x0000:0000 in x86 real mode)
Interrupt #DescriptionAddress
0Divide by zero0x0000:0000
13General protection0x0000:0340
32Timer tick (IRQ0)0x0000:0800

5. Maskable vs Non-Maskable Interrupts

  • Maskable Interrupts (IRQs): Can be enabled/disabled by the CPU
  • Non-Maskable Interrupts (NMI): Always processed; cannot be disabled

Masking allows CPUs to defer interrupt handling during critical sections.

6. Hardware Interrupts in Detail

Common examples:

  • Keyboard: Sends signal when key is pressed
  • Disk Controller: Notifies when I/O is done
  • Network Card: Indicates packet received

These are handled via Interrupt Requests (IRQs):

  • IRQ0 → System timer
  • IRQ1 → Keyboard
  • IRQ14 → Primary ATA channel

Modern systems use Advanced Programmable Interrupt Controllers (APIC) to manage interrupts more flexibly.

7. Software Interrupts

Generated by instructions like int in x86 assembly:

int 0x80  ; Linux system call interrupt

Used for:

  • System calls (trap into kernel mode)
  • Debugging (breakpoints)
  • Fault handling (divide by zero, page fault)

Trap vs Interrupt:

  • Trap = Synchronous (caused by executing instruction)
  • Interrupt = Asynchronous (external event)

8. Interrupt Service Routine (ISR)

An ISR is a small function that handles a specific interrupt.

ISR duties:

  • Acknowledge the interrupt
  • Perform necessary task (e.g., read data)
  • Possibly signal the OS (via a flag or queue)
  • Return control using special instructions (e.g., IRET in x86)

ISRs must be:

  • Fast
  • Reentrant (able to be safely interrupted)
  • Minimal (do the bare minimum, defer complex work)

9. Interrupt Prioritization and Nesting

Systems often allow interrupt nesting:

  • A higher-priority interrupt can interrupt an ISR
  • Priority levels are managed via the interrupt controller
PrioritySource
HighPower failure, NMI
MediumKeyboard, disk I/O
LowTimer, software requests

To prevent infinite nesting, the system can disable lower-priority interrupts during ISR execution.

10. Real-World Use Cases

Use CaseInterrupt Role
Real-time clocksSend regular interrupts for scheduling
Keyboard inputGenerate interrupt on keypress
MultitaskingUse timer interrupts to switch tasks
I/O operationsNotify when data is ready or transferred
Embedded systemsHandle button presses, sensor signals, etc.

11. Interrupts in OS Design

Modern operating systems rely heavily on interrupts for:

  • Context switching (via timer interrupt)
  • Device drivers (interrupt-driven I/O)
  • Signals and syscalls

The kernel sets up ISRs during boot and maps them in its interrupt descriptor table (IDT).

12. Interrupt Storms and Debouncing

Interrupt storms: Too many interrupts overwhelm the CPU (common in network-heavy environments)

Solutions:

  • Interrupt throttling
  • Polling fallback
  • Message-signaled interrupts (MSI)

Debouncing: Preventing multiple interrupts from a single button press (common in hardware/embedded)

13. Alternatives to Interrupts

MethodDescription
PollingConstantly check for events in a loop (inefficient)
DMA (Direct Memory Access)Device writes to memory directly, reducing interrupt frequency
Hybrid ModelsPolling + Interrupt combo for balanced performance

Summary

AspectDescription
DefinitionCPU halts current task to handle an event
TypesHardware, software, timer, spurious
Key ComponentsIVT/IDT, ISR, IRQs, PIC/APIC
UsageInput handling, scheduling, I/O, system calls
Handling CycleSave context → Jump to ISR → Return
OS RoleManages ISRs, maps devices, enables multitasking
RisksStorms, race conditions, missed interrupts

Interrupts are what make real-time computing possible — letting computers respond to the world in milliseconds.

Related Keywords

  • Interrupt Vector Table (IVT)
  • Interrupt Descriptor Table (IDT)
  • ISR (Interrupt Service Routine)
  • IRQ (Interrupt Request)
  • Non-Maskable Interrupt (NMI)
  • Trap
  • System Call
  • Timer Interrupt
  • Context Switch
  • APIC / PIC
  • Software Interrupt
  • Spurious Interrupt
  • Nested Interrupt
  • Interrupt Masking
  • Device Driver
  • Polling
  • DMA
  • Kernel Mode
  • IRET Instruction