Interrupts

Process scheduling is handled by the operating system. It will decide on when an application will run and for how long. However it needs help from the hardware to ensure that it always responds to their demands. For example when the hard drive is ready to serve another request or the user has pressed a key on the keyboard etc. The operating system needs to be made aware of these changes or inputs in order to decide on what course of action to take. These signals from hardware are sent to the CPU which in turn will inform the operating system. These signals are known as interrupts.

When an interrupt occurs the CPU will, on the next instruction cycle, run some special OS code to inform the OS of the interrupt. Effectively the CPU will be interrupted from its normal execution in order to deal with the interrupt. The operating system will then decide on how best to manage the interrupt. It is important for the OS to make this decision as it will know more about the context of what the user is doing. The operating, if it chooses to, can ignore interrupts.

Here is a list of common interrupts –

In order to understand the role of a interrupt it may help to consider an example. The user whishes to save a 30Mb file onto the hard drive. In order to do this the file will need to be stored in chunks. Let us imagine it saves it in 1Mb chunks for this example. The first chunk is sent to the hard drive which in turns writes it to disk. While this is occurring the CPU will continue doing other tasks such as dealing with keyboard interrupts, playing music etc. Once the hard drive has finished saving the file it will send a interrupt to the CPU requesting more data. The CPU will then send further data over to the hard drive and the cycle will continue until the file is saved.

It is important to remember that the CPU is much faster than another part of the computer, including the user. As such if the CPU waited for the hard drive to finish saving before it did anything (i.e was synchronous) then a lot of CPU cycles will have been wasted. Interrupts allow the CPU to make much better use of that time. Buffers provide the last piece of the puzzle to ensure that the hard drive always has work to do (assuming there is data still left to save!)