Interrupts In Operating System

2 minute read

python tutorial

What is an interrupt

A core responsibility of any operating system kernel is managing the hardware connected to the machine — hard drives and Blu-ray discs, keyboards and mice, 3D processors and wireless radios. To meet this responsibility, the kernel needs to communicate with the machine’s individual devices.

But there is an issue here:

  • Hardware devices are typically slower than the processor.
  • Not ideal to issue a request to a hardware device and then wait.
  • Better to be free and handle some productive work rather than waiting.

Ways to overcome the above issue

  • Polling - The kernel can check the status of the hardware periodically. There is an overhead here of checking regularly whether the hardware device is busy or not. What if the hardware device has the ability to signal to the kernel when attention is needed?

Interrupt An interrupt is an input signal to the processor indicating an event needs immediate attention. Interrupts can either be generated in response to hardware or software events.

By interrupts, we normally refer to the hardware interrupts.

Types of interrupts

Hardware or asynchronous interrupts

  • These interrupts are generated by a hardware device like keyboard, mouse, disks etc when attention is required.
  • These interrupts can arrive at any time even when the processor is in the middle of executing an instruction. Therefore, hardware interrupts are also called as asynchronous interrupts.
  • Example: When you type on the keyboard, a signal is sent to the CPU. The cpu then interrupts the running process and gives attention to this signal.

Software or synchronous interrupt

  • A software interrupt is issued by the processor itself or by some instruction that is running on the processor.
  • Since these interrupts are caused by instructions running on the processor, these are also called as synchronous interrupt.
  • Example: Divide by zero error in programs.

Types of software interrupts

Traps

  • Traps are intentionally generated by the program. A special instruction named int is executed which helps in switching from user mode to kernel mode.
  • These are called traps since it helps in trapping into the kernel space.
  • System calls are called from a program using trap since system call requires switch from user to kernel mode.

Faults

  • The program causes a recoverable error or an execption.
  • Example: Segmentation fault, page fault, divide by zero error etc.

Aborts

  • The program causes a non-recoverable error or an execption.
  • The program in this case is aborted since these types of errors cannot be caught.
  • Example: Hardware errors like corruption of disk.

Faults and aborts are a type of exceptions. Software interrupts are also sometimes called as exceptions.

In the next blog, we will see how interrupt handling happens.

Leave a comment