Interrupts in Operating System

Interrupts in Operating System

7 mins read13.8K Views Comment
Updated on Aug 23, 2023 14:07 IST

This article focuses on operating system interrupts. It also focuses on handling interrupts.

2022_07_Interrupts-in-operating-system.jpg

An interrupt is a situation that changes the order in which the processor carries out instructions. Interruption occurs when one or multiple devices send interrupt signals to the CPU. In this article, we will be studying Interrupts and their types in operating system.

Table of contents

Real-life Analogy

Suppose you are writing an assignment. Meanwhile, you get a call on the phone. So receiving that call will be on priority for you. So you will leave the writing task for a while and attend the call first. And after finishing the call, you will resume your writing work where you left off. The same concept applies when interrupts come in the computer.

Must Check: History of Operating Systems

What is an Interrupt?

Interrupts are an event that causes a program to stop and start executing another program. Interrupts are like a phone call from some device telling the program to stop executing and execute some other code instead. Most often, the device that generates an interrupt is the hardware device such as a keyboard, mouse, printer, hard drive, etc. The program itself can also generate interrupts. 

Here different devices are there which can generate interrupts via controllers.

NOTE: Interrupts are used by device driver software to communicate with the operating system. Interrupts are also used to communicate between two programs running on the computer. 

 

Memory Hierarchy in Operating System
Memory Hierarchy in Operating System
Memory hierarchy helps in organizing the memory in a way that it can minimize the access time. It is based on a program behavior that is known as locality of...read more
Working of Cache Memory in Computer
Working of Cache Memory in Computer
This article is focussed on cache memory and its different types.It also explains the working of cache memory in computer.Cache memory in computer is a small amount of random-access memory...read more
Threads and Multi-Threading: Operating system
Threads and Multi-Threading: Operating system
In any software system, there are always a variety of threads at work. These threads can be classified into two general types: user threads and kernel threads. User threads are...read more

Also explore: What is Operating Systems (OS) – Types, Functions, and Examples

Also explore: Operating system interview questions

Types of Interrupts

Interrupts are generally categorized in two categories-

1. Hardware Interrupt

Hardware interrupts are generated by interrupt request signals from peripheral circuits. hardware interrupts happen when information like the video card’s signals need to be processed.

2. Software Interrupts

Software interrupts are generated by executing a dedicated instruction. software interrupts happen when the system is waiting for a certain program to finish so that it can continue running.

Other Types of Interrupts

SVC or supervisor calls to interrupt

When the software sends an SVC to seek a specific system service, these interruptions occur. To perform the service, an SVC pauses the running program and gives control to the supervisor. 

I/O Interrupts 

An I/O interrupt is a signal that tells the processor to stop what it’s doing and deal with an input or output operation. An I/O interrupt is caused when the computer receives input from an external device. For example, if you are typing on a keyboard, the keys could be pushed down by the mechanical arm, which would be an I/O interrupt. Similarly, if you are using a scanner, the laser beam could stop midway, and this would also be an I/O interrupt

External Interrupts 

External interrupts are signals that originate outside the computer, such as keystrokes or mouse movements. They can be disruptive when they occur unexpectedly.

Restart Interrupts 

These interrupts occur when a restart SIGP (signal processor) instruction is received from another processor or the restart function at the console is selected.

Program Interrupts 

These interrupts are caused by page faults (the program references a page that is not in central storage), program errors (for example, the program attempts to perform an invalid operation), or requests to monitor an event. 

Machine check iInterrupts

Machine malfunctions cause these interrupts. When an interrupt occurs, the hardware saves relevant information about the interrupt routine and, if possible, disables the processor for more interrupts of the same type. The hardware then passes control to the appropriate interrupt handler routine. Program status words or PSWs are an essential resource in this process.

Segmentation Technique in Operating System
Segmentation Technique in Operating System
Have you ever found yourself tapping your fingers impatiently while your computer takes its sweet time to load a program or file? It’s a common problem that many of us...read more
Memory Management Techniques in Operating System
Memory Management Techniques in Operating System
Memory management is very important aspect of operating system performance.In this article we have covered different memory management techniques like paging,swapping,compaction and segmentation. This article covers different topics related to...read more
Functions of Operating System
Functions of Operating System
An operating system (OS) is software that manages computer software and hardware resources. Different operating systems have different app stores and could have different applications in them, too. This article...read more

Read: Operating System Online Courses & Certifications

How CPU Responds to Interrupts

Whenever an interrupt is generated by high priority process, the CPU stops executing the program’s code and executes the code associated with the interrupt. When the CPU finishes executing the code associated with the interrupt, it resumes the execution of the code of the program that was running. Changing from executing the code of one program to executing the code of another, called context switching, is very time-consuming. Therefore, interrupts are executed as quickly as possible so that the program can resume execution after the interrupt is over.

Enabling Disabling Interrupts

PC manufacturers employ disabling interrupts as part of their design process. They determine which interrupts need to be disabled and let the operating system handle these interrupts. On traditional processors, disabling interrupts requires adding and maintaining code in a processor’s firmware.

Modern CPUs disable interrupts by default. Some computer components, such as disk controllers, handle interrupts and usually do not need to be disabled. Other components, such as the video card, need to be disabled because they generate many interrupts.

When an interrupt is enabled, the device that generates the interrupt can send the interrupt to the CPU. Interrupts are disabled when the device that generates the interrupt is not working correctly. Interrupts are also disabled when the program does not want to be interrupted by the device that generates the interrupt.

We have an option to enable and disable interrupts. Disabling interrupts allows the CPU to carry out individual tasks without having to execute the tasks simultaneously. This saves energy, as the CPU can devote more resources to carrying out tasks specific to the task at hand instead of carrying out tasks common to several tasks.

Interrupt Latency

Interrupt latency is the time that elapses between when an interrupt is generated and when the interrupt is handled. Interrupt latency is determined by several factors, like how many interrupts are generated, how many interrupts are enabled, how many interrupts can be handled, and how long it takes to service each interrupt. Interrupt latency is necessary when the device that generates the interrupt requires a certain amount of time to generate the interrupt. For example, when a printer is printing a document, the computer must pause running the program that is printing the document until the printer finishes printing the document. The time the computer must pause running the program is the interrupt latency.

Interrupt Handling in Computer

Interrupts are handled on the computer by special software called an interrupt handler. There can be multiple interrupt handlers installed on a computer. The interrupt handler that is executed by the CPU depends upon the type of interrupt that is generated. 

The interrupt_handler becomes active when an interrupt occurs, and the processor or controller cycle is interrupted or stopped. The interrupt handler recognizes the type of interrupt and executes the instruction immediately. 

Most interrupts are asynchronous type. This interrupt_handler is commonly known as the Interrupt Service Routine (ISR). Each device has a different type of interrupt handler.

Modern computer systems use a technique called interrupt service request (ISR). This allows the operating system to run the instructions in an interrupt context without getting into the regular program flow. This gives the system more flexibility and the ability to run more than one instruction at a time. The ISR handler can keep track of which instructions it has already run and can do things like cancel other scheduled instructions if they need to switch focus to handling the new interrupt.

 Steps of Interrupt Handling

  • Suppose the CPU is performing task 1, and meanwhile, an interrupt comes to execute task 2(high priority)
  • The operating system preserves the state of the CPU by storing registers and the program counter of task 1. And do context switching(shifting to a new process).
  • Determines which type of interrupt has occurred.
  • Determine what action should be taken for each type of interrupt.
  • After performing task 2, the CPU resumes the already running process(task 1) from the same state where it left.

Conclusion

Interrupts are used by device driver software to communicate with the operating system. With technological advances, interrupt handling has become more efficient and faster. The advantages of interrupts in computers are that they provide device independence, can be used to break up large tasks into smaller tasks, provide concurrency, and provide a way to respond to external events. The disadvantages of interrupts are that they consume processor time and cause a context switch.If you liked the article then please like it and share it with your friends.

Stay tuned for other exciting blogs on the operating systems!!

FAQs

What are interrupts?

An interrupt is an event that occurs to stop the current execution of the current process and notify the operating system to service an interrupt service routine (ISR). The ISR is responsible for identifying the software or hardware that caused the interrupt and notifying the CPU of it.

What are software interrupts?

A software interrupt usually occurs when the process encounters an exception or uses a special instruction that causes an interrupt. Our system has system calls, but usually software interrupts. Division by zero throws the exception that caused the software interrupt, but while using the fork() system call, fork() also invokes the software interrupt.

What are hardware interrupts?

When an external device wants to get the operating system's attention to handle a particular request, it triggers an interrupt called a hardware interrupt. All external devices are connected to one interrupt request line, which is used for interrupts.

About the Author

This is a collection of insightful articles from domain experts in the fields of Cloud Computing, DevOps, AWS, Data Science, Machine Learning, AI, and Natural Language Processing. The range of topics caters to upski... Read Full Bio