What is Context Switch?
- When the processor moves from one process to another process, it is called context switch. The CPU will be deallocated from the old process and the new process will get the CPU control.
- Switching the CPU from one process to another requires saving the state information of the old process and loading the saved state information for the new process.
- The context of a process is represented in the PCB for a particular process.
- It includes the value of CPU registers, the process state and memory management information.
- When a context switch occurs, the kernel saves the context of an old process in its PCB and loads the saved context of a new process for scheduling and then executes it.
- A context switch time is a time between moving from one process to another by the CPU.
- This time is an overhead because the system does not perform useful work while switching.
- The context switch time varies from machine to machine depending on memory speed, number of registers that must be copied and the existence of special instructions.
- Context switch time is also dependent upon hardware support like wait for input-output, reading and writing a file etc.