What is a context switch?

A context switch (also sometimes referred to as a process switch or a task switch) is the switching of the CPU (central processing unit) from one process or thread to another.

Context switching can be described in slightly more detail as the kernel (i.e., the core of the operating system) performing the following activities with regard to processes (including threads) on the CPU: (1) suspending the progression of one process and storing the CPU's state (i.e., the context) for that process somewhere in memory, (2) retrieving the context of the next process from memory and restoring it in the CPU's registers and (3) returning to the location indicated by the program counter (i.e., returning to the line of code at which the process was interrupted) in order to resume the process.

A context switch is sometimes described as the kernel suspending execution of one process on the CPU and resuming execution of some other process that had previously been suspended. Although this wording can help clarify the concept, it can be confusing in itself because a process is, by definition, an executing instance of a program. Thus the wording suspending progression of a process might be preferable.


It usually refers to switching between threads or processes. Wikipedia has a more thorough description.


Context switch is the switching of the CPU from one process/thread to another process/thread.

People sometimes use the term context switch outside of the specific computer world to reflect what they are doing in their own lives. "If I am going to answer that question, I need to context switch from thinking about A to thinking about B".

Wikipedia


It is the process of switching between processes on a CPU.