When the execution of one process’s instructions on the CPU must pause due to an interrupt that occurred, the OS must save the current execution state of the process before it handles the interrupt because the OS needs to run the interrupt handler software on the CPU.
In such a state-save action, the operating system copies the process’s data from the CPU to memory. When the OS is ready to resume the execution of the process on the CPU, it performs a state-restore action, in which the process’s data is copied from memory back to the CPU.
The same also happens when we remove one process from the CPU in favor of another process that will run there (remember that the OS does this often to create the sense that processes run simultaneously.) The procedure of saving the state of one process, removing it from the CPU, and then restoring the state of a different process on the CPU is called a context switch. Context switches happen extremely frequently, so the operating system performs them very fast.