Operating System Interview Questions · Question 29

What is the difference between an interrupt and an exception?

Interview preparation resource from Gate Smashers.

Interview-ready answer

An interrupt is usually an asynchronous event from external hardware, while an exception is a synchronous event caused by the current instruction or an explicit software trap.

Understand it clearly

Timers, keyboards, network devices and storage completion signals can interrupt the processor independently of the instruction being executed. The CPU saves enough state, identifies the interrupt source and runs the registered kernel handler.

Exceptions are directly related to execution: examples include divide-by-zero, invalid opcodes, page faults and system-call traps. Some are recoverable and allow the instruction to restart, while others cause a signal or process termination. Both use controlled CPU entry mechanisms, but their sources and timing differ.

A timer interrupt can arrive between instructions regardless of the current program, while a divide-by-zero exception is caused by the instruction being executed. In both cases the CPU saves controlled state and transfers execution to an appropriate kernel handler.

Quick comparison
BasisInterruptException
SourceUsually external hardwareCurrent instruction or software
TimingAsynchronousSynchronous
ExamplesTimer or device completionPage fault, trap or divide-by-zero
Instruction linkIndependentDirectly related