Context Switching
A context switching sometimes referred as a task switch or a process switch. Basically this context switching is the switching of the CPU from one process/thread to another one. A process which also sometimes referred as a task is running instance of a program. A context switching is the procedure to restore and store the state of context of CPU in process control block(PCB) so that the process execution can be resumed from the same point at a later time. This context switching technique enables multiple processes to share a single CPU. This context switching is a major feature of a multitasking operating system. Whenever the scheduler switches the CPU from a process to execute another process in this case the context switcher saves the contents of all the processors registers for the process which is being removed from the CPU in it process descriptor.
PCB of a process is used to represent the context of a process. Context switch time is pure over-head. The context switching can expressively affect the performance such as modern computers have several general and status registers to be saved. The intervals of context switching are highly depended on the hardware provision. (n+m) bxK time units is required to switch the context to save the state of the processor with n general registers b is assumed as the store of operations which are required to save n and m registers of two process control block (PCB) and K time unit is required to store each instruction. Context switching is shown as:
In some hardware systems there employ two or more sets of processors registers to reduce the amount of context switching time. Whenever the process is switched following information is stored:
- Program counter
- Scheduling information
- Base register’s and limit register’s value
- Registers which are currently being used
- Changed state
- I/O state
- Accounting info