An interrupt is a signal sent to the CPU from either hardware or software that temporarily halts the CPU's current activities and allows a special routine, known as an interrupt handler or interrupt service routine (ISR), to run. The CPU saves its current state, switches to the ISR, and resumes its previous task afterward.
Interrupts are vital for efficient multitasking, allowing the CPU to respond quickly to events like input from a keyboard, mouse, or hardware failures without polling these devices.
Polling is a technique where the CPU continuously checks the status of a device or resource at regular intervals to see if it requires attention. Unlike interrupts, where the device sends a signal to the CPU when it’s ready, polling requires the CPU to actively query the device in a loop.
These are generated by hardware devices like keyboards, network cards, or timers. They are asynchronous, meaning they occur independently of the CPU's current execution. When a device needs attention (e.g., key press, packet arrival), it sends a signal to the CPU to trigger an interrupt.
These are generated by software or the operating system itself and are triggered by executing special instructions. Software interrupts are often used for system calls, where an application requests services from the OS.
These occur when CPU detects an error or specific condition during execution, such as division by zero or an invalid memory access. Exceptions are often treated similarly to interrupts but are generated by the CPU itself.
