Question-1 What is interrupt? How it is handled by an OS?
- A software interrupt is caused either by an exceptional condition in the processor itself, or a special instruction in the instruction set which causes an interrupt when it is executed.
- The former is often called a trap or exception and is used for errors or events occurring during program execution that is exceptional enough that they cannot be handled within the program itself.
- Interrupts are a commonly used technique for process switching.
- Associated with each I/O device class (e.g., floppy disks, hard disks etc…) there is a location (often near the bottom of memory) called the interrupt vector.
- It contains the address of the interrupt service procedure.
- Suppose that user process 3 is running when a disk interrupt occurs.
- User process 3’s program counter, program status word, and possibly one or more registers are pushed onto the (current) stack by the interrupt hardware.
- The computer then jumps to the address specified in the disk interrupt vector.
- That is all the hardware does.
- From here on, it is up to the software, in particular, the interrupt service procedure.
- All interrupts start by saving the registers, often in the process table entry for the current process.
- Then the information pushed onto the stack by the interrupt is removed and the stack pointer is set to point to a temporary stack used by the process handler.
- When this routine is finished, it calls a C procedure to do the rest of the work for this specific interrupt type.
- When it has done its job, possibly making some process now ready, the scheduler is called to see who to run next.
- After that, control is passed back to the assembly language code to load up the registers and memory map for the now-current process and start it running.
- Interrupt handling and scheduling are summarized in Figure above.
You may be interested in:
Operating System Short Descriptive Questions and Answers