A context switch is the process of saving and restoring the state of a CPU (context (information engineering)) so that multiple processes can share a CPU. Context switching is an essential feature of multitasking operating systems. Since context switches usually require a lot of computer processing, it is important to optimize the context switch in the design of the operating system.
[* Wikipedia](https://ja.wikipedia.org/wiki/%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3% 83% 88% E3% 82% B9% E3% 82% A4% E3% 83% 83% E3% 83% 81)
--In a multi-process environment ** when the CPU is running one process ** and ** when the next priority process due to an interrupt request must be executed **, the state of the existing process Alternatively, the work of saving the register value (Context) and changing the state of the new process or the register value (Context) ** so that the CPU can perform the next process ** is called Context Switch (Context Switching).
--Information that defines the current status of users and other users, people, locations, objects, etc. that are affected by the interaction between users and systems or devices.
--There is also a Context for Andoroid and Servlet, but ** Context in OS is process information for the CPU to execute the corresponding process **.
--This Context is saved in the process's PCB (Process Control Block), and the PCB information can be read during Context Switching (loading) and the CPU can continue the work that the previous process was doing.
--Process state --Generation --Preparation --Execute --Waiting --Cancelled
--Program counter --The next address the process will execute
--Process number
Context Switching - Interrupt Interrupt is when the CPU is executing a program, an exception occurs from outside the running program and processing is required. It means telling the CPU so that it can handle exceptional situations.
So what kind of interrupt request will cause Context Switching? -I / O request (input / output request) -Time slice expired (when CPU usage time expires) -Fork a child (when creating a child process) -Wait for an interrupt (when waiting for Interrupt processing)
There are other laws, but I will omit the details.
Recommended Posts