operating-systems

Definition

Interrupt

An interrupt is an asynchronous signal sent to the processor by hardware or software indicating an event that requires immediate attention. Unlike traps, interrupts are typically caused by events external to the currently running process.

Mechanism

Upon receiving an interrupt, the system follows a specific sequence to handle the event while preserving the state of the interrupted process:

  1. Hardware Handover: The CPU completes the current instruction, saves the program counter and PSW onto the system stack, and loads a new PC from the interrupt vector Hardware.
  2. Context Save: The OS saves all general-purpose registers and sets up a new stack for the handler Assembly code.
  3. Service Routine: The specific interrupt service routine (ISR) executes (e.g., reading data from a keyboard buffer) C code.
  4. Scheduling: The OS scheduler decides which process should run next (this may trigger a process switch) C code.
  5. Context Restore: The OS restores the registers and prepares the CPU to resume execution of the selected process Assembly code.

Visual Representation

Common Sources

  • Timer Interrupts: Used by the OS to implement Timeouts and multitasking.
  • I/O Interrupts: Signals from devices (keyboard, network, disk) that an operation has completed or data is available.
  • Hardware Failures: Power loss or memory parity errors.