Interrupt
- In Turkish
- kesme
In short
An interrupt is a signal to the CPU that an event needs immediate attention, making it pause its current work and run a special handler in the kernel.
What is an interrupt in computing?
An interrupt is how hardware devices and software tell the CPU that something has happened: a key was pressed, a network packet arrived, a disk finished reading, or a timer ran out. Without interrupts, the CPU would have to keep checking every device to see whether it needed anything, which wastes time and power.
When an interrupt arrives, the CPU finishes its current instruction, saves the state of what it was doing, switches to kernel mode, and looks up the matching handler in an interrupt table set up by the kernel. The handler, called an interrupt service routine, deals with the event, and then the CPU restores the saved state and resumes where it left off. Handlers must be very quick, so kernels usually split the work: a short first part acknowledges the device, and the rest is deferred to run a little later. Interrupts come from devices (hardware interrupts, or IRQs), from a timer that lets the scheduler preempt running tasks, and from the CPU itself when an instruction causes an exception such as a page fault or division by zero.
An interrupt works like a doorbell. You don't walk to the front door every minute to check for visitors; you keep cooking until the bell rings, answer it, and then return to the recipe. Interrupts are what make keyboards and mice feel instant, let the operating system share the CPU fairly, and let idle processors sleep until real work arrives.
Interrupts are often contrasted with polling, where software repeatedly checks a device instead of waiting to be notified; very fast network cards sometimes switch to polling under heavy load because handling millions of interrupts costs more than checking. An interrupt is also different from a Unix signal: interrupts are delivered to the CPU and handled by the kernel, while signals are notifications the kernel delivers to a user process. Exceptions in programming languages, handled with try and catch, are a separate, language-level mechanism.
Key takeaways
- An interrupt makes the CPU pause its current work to handle an urgent event.
- The kernel runs a matching interrupt handler and then resumes the interrupted work.
- Hardware devices, timers, and CPU exceptions can all raise interrupts.
- Timer interrupts make preemptive CPU scheduling possible.
- Interrupts avoid the waste of constantly polling devices.
Example
# How many interrupts each CPU core has handled, per device
head -n 10 /proc/interrupts
# Interrupts ("in") and context switches ("cs") per second, 5 samples
vmstat 1 5Readers ask
What is the difference between an interrupt and polling?
With polling, the CPU repeatedly asks a device whether it needs attention. With interrupts, the device notifies the CPU only when something happens, which usually saves time and power.
What is an IRQ?
IRQ stands for interrupt request, the signal a hardware device sends to request the CPU's attention. Each device or device queue is assigned an IRQ number so the kernel knows which handler to run.
What is an interrupt handler?
An interrupt handler, or interrupt service routine, is the kernel or driver code that runs in response to a specific interrupt. It must finish quickly, so longer work is usually deferred to run afterward.
See also
- KernelOperating Systems, p. 17A kernel is the core part of an operating system that manages the CPU, memory, and hardware devices and controls how programs get access to those resources.
- CPU SchedulingOperating Systems, p. 6CPU scheduling is how an operating system decides which ready process or thread runs on each CPU core next, and for how long, so the processor is shared fairly.
- Context SwitchOperating Systems, p. 3A context switch is when the operating system saves the state of the running thread or process and restores another one's state so it can use the CPU.
- Device DriverOperating Systems, p. 9A device driver is software that lets the operating system control a specific piece of hardware, translating generic OS requests into device-specific commands.
- Unix SignalOperating Systems, p. 35A Unix signal is a short asynchronous notification the kernel delivers to a process to report an event, such as a stop request, an error, or an expired timer.
- System CallOperating Systems, p. 31A system call is a request from a program to the operating system kernel to perform a privileged action, such as reading a file or starting a process.
Spotted a mistake or something missing on this page?Suggest an edit