0
2.6kviews
Saving the Context of a Process
1 Answer
0
79views

Interrupts and Exceptions

Handling interrupts and exceptions is an important responsibility of the system. If the system is under execution and processor is at a lower level, and if an interrupt occurs, the kernel accepts the interrupt first, before decoding the next instruction. After that, it raises the processor execution level to a higher level and blocks other interrupts.

It handles the interrupt by performing following sequence of operations:

  • It stores the current register context of the executing process and creates (pushes) a new context layer.

  • The kernel finds out the reason or source of the interrupt, and if possible, it also searches the unit number of the driver which caused the interrupt.

  • When the system receives an interrupt, it gets a number. It uses that unit number as an index into the interrupt vector, which stores the actions to be taken (interrupt handlers) when interrupts occur.
  • The kernel calls the interrupt handler. The kernel stack of the new context layer is logically different from the kernel stack of the previous context layer. Some implementations use the processes kernel stack to store the stack frame of an interrupt handler, while some implementations use a global interrupt stack for the interrupt handlers which makes sure to return without a context switch.
  • The kernel returns from the interrupt handler and executes a set of hardware instructions which restore the previous context. The interrupt handler can change the behavior of the process. e.g., it may modify the kernel data structures. But in general, the process resumes execution as if the interrupt never occurred.

enter image description here

The algorithm for interrupt handling is given below:

/* Algorithm: int_handling
* Input: null
* Output: null
*/
{
    store (push) current context layer;
    find out the source of interrupt;
    find interrupt vector;
    call interrupt handler;
    restore (pop) previous context layer;
}

Example of state of the context layer as stack as system call is executed and interrupts occur:

enter image description here

Please log in to add an answer.