- It is switching the context of the process from user space to kernel space.
- It involves saving the current context of a process before moving the control of execution to kernel space.
- The current context of the process that is the current register content, program counter all are saved so that it can be reloaded once the control switches back to the user space program.
- When programs run, they build up a great deal of state in CPU caches, TLBs. Switching to another job causes this state to be flushed and a new state relevant to the currently-running job to be brought in, which may exact a noticeable performance cost.
- Context switching is the basis of multiprogramming or multi-tasking.
Before the context is switched to the kernel space, the complete process control block(PCB) which is nothing but a data structure to holds the information’s about the process is saved onto the stack.
Important information present in PCB which are saved onto the stack is as follows:
- The process state
- The program counter
- The values of different registers.
- The CPU scheduling information.
- Memory Management information about the process
- I/O status information.
When the PCB of the currently executing process is saved, the operating system loads the PCB of the next process that has to be run on CPU. This is a heavy task and it takes a lot of time.
Thus having frequent context switching is an overhead and involves the scheduler picking ready jobs to be processed.
Overhead of Context Switching:
Direct Factors:
- Latency
- Saving/restoring contexts
- Finding the next process to execute, calling the scheduler
Indirect Factors:
- TLB needs to be reloaded.
- Processors pipeline to be Flushed.
Diag-1: Context Switching

Related Posts:
- Process vs program
- Sections of a process
- States of a process
- Process Control Block(PCB)
- Attributes of a process
- Termination of a process
Categories: Operating system (OS)
Leave a Reply