In computer science, an interrupt is a short-term interruption of the normal execution of a program, in order to process a usually short, but time-critical, process. The triggering event is called an interrupt request (IRQ). After this request, the processor executes an interrupt handler, interrupt service routine, or ISR. The interrupt routine is executed with extended privileges (on appropriate processors). Following the interruption routine, the processor is restored to its previous state (including privilege) and the interrupted program execution is resumed where it was interrupted.
Interrupts (more precisely: hardware interrupts) are triggered by asynchronous external events. Asynchronous in this context means that the running program execution is not always interrupted at the same point. In contrast, in many processors, an interrupt can also be triggered by the running program code itself by means of a machine instruction (“INT nn”) (software interrupt). Effectively, this is more akin to a subroutine call; individual operating systems implement system calls in this way.
The keyboard sends an interrupt request when a key is pressed. To do this, a signal is placed on the bus or directly on a processor pin (IRQ input) intended only for this purpose. The interrupter can then read the character from the keyboard control and forward it to the application.
---
The mouse sends an interrupt request when the axis position of the device is changed or a mouse button is pressed. Two mouse buttons are supported as a hardware interrupt (hardware mouse). Mouse gestures such as double-clicking must be detected by the software, such as an operating system. Additional buttons on a mouse are only supported by appropriate device drivers.
Types of Interrupts
Interrupts can be classified into several types based on their origin, source, and functionality:
- Hardware Interrupts: Hardware interrupts are generated by external hardware devices to notify the CPU of events requiring attention, such as I/O (Input/Output) operations, timer expirations, or hardware errors. Examples include keyboard interrupts, mouse interrupts, and disk I/O interrupts.
- Software Interrupts: Software interrupts, also known as traps or exceptions, are generated by the CPU itself or software processes to invoke specific software routines or handle exceptional conditions. Software interrupts can be triggered by system calls, arithmetic errors, or programmatic instructions such as breakpoints.
- Maskable Interrupts: Maskable interrupts are interrupts that can be temporarily disabled or masked by the CPU using interrupt masking mechanisms. These interrupts can be prioritized and selectively enabled or disabled based on their importance and urgency.
- Non-Maskable Interrupts (NMI): Non-Maskable Interrupts are interrupts that cannot be disabled or masked by the CPU and are typically reserved for critical system events such as hardware failures or power loss. NMIs take precedence over other interrupts and require immediate attention from the CPU.

Purpose of Interrupts
An interrupt is used to respond immediately to an input or output (e.g. from a keyboard, hard drive, network, or timer) while another program (such as a user application) is being processed. The interface hardware only needs to trigger an interrupt if the next interface operation is not possible, for example when buffer is empty (output), buffer is full (input), error messages from the interface hardware, or when there is no data transfer event (for example, timer).
Advantages over polling
In addition to interrupts, there is only the technique of programmed (cyclic) querying (polling) to find out the status of input/output devices, processes or other things. While this method is simpler and doesn’t require any additional hardware, it’s much less efficient than working with interrupts because it puts a lot more strain on the CPU. In addition, the speed of response in polling depends on how much time elapses between queries, which can be critical in situations that require an immediate response. In the case of multitasking operating systems, polling is not possible as the sole method.
The standard analogy for interrupts in everyday life is a door with a bell: while you are doing your tasks, you can be interrupted by the bell at any time when a guest wants to “work through” and then turn to him. In the case of polling – i.e. without a bell – you would have to check the door again and again to see if there are visitors or not. When heating milk, on the other hand, it is probably better not to wait for the “interrupt” of boiling over, but to monitor the process regularly.
Application examples
As an example of an application of interrupts, one can imagine a processor that, after giving an order to a hardware component, does not actively wait for its response (polling), but performs other tasks until that hardware component draws its attention to itself again by means of an interrupt. Without interrupts, for example, preemptive (= displacing running programs) multitasking operating systems would be impossible, since without them programs could no longer be interrupted, switched by the operating system (timeshare) and input/output devices could no longer be operated.
Tagged With usual7jw