Operating System Design/Processes/Interrupt

Many pieces of hardware send interrupt signals to the CPU. When the CPU notices that signal, it does a hardware interrupt ‒ the CPU performs a context switch, saving some information about what it was doing, then jumps to execute the "interrupt handler" associated with that particular hardware interrupt. For example, when a user types into a keyboard, the keyboard sends a key interrupt. The CPU then executes code for a key interrupt, which typically displays a character on a screen or performs a task.

Perhaps the most important interrupt for operating system design is the "timer interrupt", which is emitted at regular intervals by a timer chip.

A software interrupt, also called a processor generated interrupt, is generated by the processor executing a specific instruction. Common processor-generated-interrupts are the divide-by-zero exception and the general-fault or page-fault exception. Software interrupts cause a context switch to an interrupt handler similar to a hardware interrupt.

Some interrupt handler software might reset the machine, or just display the error, but most interrupt handlers do one of 3 things:
 * The hardware (such as a video display) signals it is ready for the next piece of data, the interrupt handler sends out the next piece of data, then returns to the process that was interrupted.
 * The hardware (such as a keyboard) signals that it has a piece of data available, the interrupt handler reads in that piece of data, then returns to the process that was interrupted.
 * The timer interrupt handler runs the OS scheduler. If the process that was just interrupted has used up its time quantum, and there is some other runnable process, then the scheduler "returns" to that other process. (Later, when the timer interrupts some other process, the scheduler will "return" to this process).