Context Switching in Operating System

For Complete YouTube Video: Click Here

In this class, we will try understanding Context Switching in Operating System.

We have discussed the process control block and process state diagram in our previous classes.

Context Switching in Operating System

To understand this concept, we will consider the image shown below.

In the above diagram, we have two processes, P1 and P2.

Assume that process P1 is executing and in the running state.

Once the allocated time is completed or any IO operation occurs, it will be switched to the “ready or wait” state, and it has to provide room for another process into the run state.

In our case, process P2 has to be switched to the running state.

The above diagram shows the values 10, 20, and 30 in the registers R1, R2, and R3.

When P1 is ready for switching, values of those variables must be saved, and the values of the process P2 have to be stored in the corresponding registers. This switching of the process is called context switching.

Context switching is an overhead to the overall system’s performance because, at the time of context switching, the CPU will sit ideally.