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
Difference Between Interrupt and Polling in OS
An operating system acts as a bridge between hardware and applications. The CPU handles all system tasks, but sometimes situations arise when it's required to interrupt the currently running task and take rapid action. Therefore, operating systems use two methods: interrupt and polling for dealing with such events. Both methods pause the CPU from its current work and make it execute essential tasks.
Both interrupt and polling differ significantly from each other in several ways. In this article, we will discuss the important differences between interrupt and polling in operating systems.
What is Interrupt?
A signal to the CPU to take immediate action is called an interrupt. An interrupt is a mechanism that notifies the CPU when it requires attention. The interrupt is considered a hardware mechanism that requires the operating system to stop and determine what to do next.
When an interrupt occurs, the CPU stops executing the current program and transfers control to an interrupt handler or interrupt service routine. There are two types of interrupts:
-
Hardware interrupts − Generated from external devices and I/O devices
-
Software interrupts − Generated from internal devices and software programs
Interrupts reduce the idle time of the CPU by allowing it to respond immediately to device requests rather than continuously checking for them.
What is Polling?
Polling is a process where the CPU constantly checks the status of devices to see if they need attention. It is a protocol in which the CPU services I/O devices by periodically checking their status to determine if it's time for the next I/O operation.
In polling, devices do not require continuous attention, but when one does need service, it must wait until the polling program next checks it. This results in wasted CPU time on unnecessary polls, making polling an inefficient method compared to interrupts.
Difference between Interrupt and Polling
The following table highlights the important differences between interrupt and polling in operating systems:
| Interrupt | Polling |
|---|---|
| A mechanism that notifies the CPU when it requires attention | A process where the CPU constantly checks device status to see if it needs attention |
| Considered a hardware mechanism | A protocol implemented in software |
| An interrupt handler services the device | The CPU directly services the device |
| Interrupt-request line indicates device needs servicing | Command-ready bit indicates device needs servicing |
| CPU is used only when a device requires servicing | CPU must wait and check if a device needs servicing |
| Saves CPU cycles by responding only when needed | Wastes CPU cycles on unnecessary checks |
| Can occur at any point in time (asynchronous) | CPU polls devices at regular intervals (synchronous) |
| Becomes inefficient if devices frequently interrupt the CPU | Becomes inefficient when devices rarely need servicing |
Conclusion
The key difference between interrupt and polling is that interrupt is a hardware mechanism where devices signal the CPU when they need attention, while polling is a software protocol where the CPU continuously checks device status. Interrupts are generally more efficient as they eliminate unnecessary CPU cycles spent checking idle devices.
