In computer engineering, an interrupt is a signal from a device to the kernel, which typically results in a context switch.

Digital computers usually provide a way to start software routines in response to asynchronous electronic events. These events are signalled to the processor via interrupt requests (IRQ). The processor and interrupt code make a context switch into a specifically written piece of software to handle the interrupt. This software is called the interrupt routine.

Interrupts were originated to avoid wasting the computer's valuable time in software loops waiting for electronic events. Instead, the computer was to do other, useful work. The interrupt would signal the computer to complete the work that had been waiting for some slow mechanical device. Computers are now so cheap that this argument makes less sense.

Interrupts remain in modern computers because they permit a computer to have prompt responses to electronic events, while performing other work.

The waiting still occurs. Normally, the computer's microcode continually tests for an interrupt.

A well-designed interrupt mechanism arranges the design of the computer bus, software and interrupting device so that if some single part of the interrupt sequence fails, the interrupt restarts and runs to completion. Usually there is an electronic request, an electronic response, and a software operation to turn off the device's interrupt, to prevent another request.

Typical interrupt types include:

  • timer interrupts
  • disk interrupts
  • power-off interrupts

Other interrupts exist to transfer data bytes using UARTs, or Ethernet, sense key-presses, control motors, or anything else the equipment must do.

A classic timer interrupt just interrupts periodically from a counter or the power-line. The software (usually part of an operating system) counts the interrupts to keep time. The timer interrupt may also be used to reschedule the priorities of running processes. Counters are popular, but some older computers used the power line because power companies control the power-line frequency with an atomic clock.

A disk interrupt signals the completion of a data transfer from or to the disk peripheral. A process waiting to read or write a file starts up again.

A power-off interrupt predicts or requests a loss of power. It allows the computer equipment to perform an orderly shutdown.

Interrupt routines generally have a short execution time. Most interrupt routines do not allow themselves to be interrupted, because they store saved context on a stack, and if interrupted many times, the stack could overflow. An interrupt routine frequently needs to be able to respond to a further interrupt from the same source.

Processors also often have a mechanism referred to as interrupt disable which allows a software to prevent interrupts from interfering with communication between interrupt-code and non-interrupt code. See mutual exclusion.

Typically, the user can configure software so that different types of interrupts are enabled or disabled, depending on what the user wants. The interrupt signals are And'ed with a mask, thus allowing only desired interrupts to occur. Some interrupts cannot be disabled - these are referred to as nonmaskable interrupts.