Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a context switch?

Tags:

I was reading about the debuggerstepperboundary attribute and a site says it is is useful in a context switch.

What exactly is a context switch? I'm assuming it is a switch from one thread to another, or in execution or security context? However, these are not particularly educated guesses so I'm asking here.

like image 498
GurdeepS Avatar asked Nov 18 '08 21:11

GurdeepS


People also ask

What is context switching?

A context switch is a procedure that a computer's CPU (central processing unit) follows to change from one task (or process) to another while ensuring that the tasks do not conflict. Effective context switching is critical if a computer is to provide user-friendly multitasking.

What is context switching example?

Example of Context SwitchingSuppose that multiple processes are stored in a Process Control Block (PCB). One process is running state to execute its task with the use of CPUs. As the process is running, another process arrives in the ready queue, which has a high priority of completing its task using CPU.

What is context switch and when does it occur?

A context switch occurs when a computer's CPU switches from one process or thread to a different process or thread. Context switching allows for one CPU to handle numerous processes or threads without the need for additional processors.

Why do we use context switching?

The term context switching was originally used in computing to describe the switching of the CPU from one state of a process to another. Computers struggled when they switched tasks, incurring a context switch cost. Today, we use multitasking and context switching to speak about human behaviors.


1 Answers

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.

like image 152
Brian Liang Avatar answered Oct 29 '22 17:10

Brian Liang