Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
What are different types of interrupts?
An interrupt is a signal from a device attached to a computer or from a program within the computer that requires the operating system to stop and figure out what to do next. Interrupts allow the system to respond immediately to important events without constantly checking for them.
When the CPU processes programs and needs any I/O operation, the interrupt mechanism prevents the CPU from remaining idle while waiting for I/O completion. Instead of continuously polling devices, the CPU can work on other tasks and respond only when an interrupt signals that an operation is ready.
How Processor Handles Interrupts
When an interrupt occurs, it causes the CPU to stop executing the current program and transfer control to an interrupt handler or interrupt service routine (ISR).
Step-by-Step Interrupt Handling
Step 1 − When an interrupt occurs while the processor is executing instruction i, the program counter points to the next instruction (i+1).
Step 2 − The current program counter value is stored on the process stack, and the program counter is loaded with the address of the interrupt service routine.
Step 3 − Once the interrupt service routine completes, the saved address is popped from the process stack and placed back in the program counter.
Step 4 − Normal execution resumes from instruction (i+1).
Types of Interrupts
Hardware Interrupts
Hardware interrupts are signals generated by external devices and I/O devices when they need CPU attention. For example, when you press a key on the keyboard, it generates a signal to the processor to perform the corresponding action.
Maskable Interrupt − Hardware interrupts that can be delayed when a higher-priority interrupt has occurred. The CPU can temporarily disable these interrupts.
Non-Maskable Interrupt (NMI) − Critical hardware interrupts that cannot be delayed and must be serviced immediately by the processor, such as power failure or memory errors.
Software Interrupts
Software interrupts are signals generated by programs when they need to access system services or when exceptional conditions occur during execution.
Normal Interrupts − Interrupts caused by software instructions, such as system calls when a program requests operating system services.
Exception − An unplanned interruption during program execution. For example, division by zero, invalid memory access, or arithmetic overflow conditions.
Comparison
| Type | Source | Timing | Examples |
|---|---|---|---|
| Hardware Maskable | External devices | Can be delayed | Keyboard, mouse, timer |
| Hardware Non-Maskable | Critical hardware | Immediate | Power failure, memory parity error |
| Software Normal | Program instructions | Synchronous | System calls, software timers |
| Software Exception | Program errors | Synchronous | Division by zero, page fault |
Conclusion
Interrupts are essential for efficient system operation, allowing the CPU to respond to hardware events and software requests without wasting time in idle waiting. Understanding the different types of interrupts − maskable/non-maskable hardware interrupts and normal/exception software interrupts − is crucial for system programming and operating system design.
