written 5.7 years ago by | • modified 5.7 years ago |
Interrupt causes the operating system to change a CPU from its current task and to run a kernel routine.
When an interrupt occurs, the system need to save the current context of the process running on the CPU, so that it can later restore when needed.
Switching the CPU to another process required performing a state save of the current process and state restore of different process and this task is known as context switching.
When a context switch occur the kernel switching context of old process in d’s PCB and loads the saved context of its new process scheduled to run.
Context switch time is pare overhead, because system does not do any useful work during this time.
It is highly depending on hardware support like if processor having large number of register so it wont need to unload old PCB as it has space enough to store all frequently used processes PCB.
Action taken by kernel to context switch between processes.
In response to clock interrupt, the OS saves the PC and user stack pointer of the current executing process and transfer control to kernel clock interrupt handler.
The clock interrupt handler saves the rest of the register as well as other machine state such as state of floating pointer registers in the process PCB.
The OS invoke the schedule to determine the next process to execute.
The OS then retrieves the state of next process from cts PCB and restore the registers.
This restore operation takes the processor back to the state in which this process was previously interrupted, executing in user mode with user mode privileges