What is a Context Switch?

what-is-context-switching-in-operating-system-context-switching-flow.png

What is a Context Switch?

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).

What is Context?

--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.

PCB (Process Control Block) storage information

--Process state --Generation --Preparation --Execute --Waiting --Cancelled

--Program counter --The next address the process will execute

--Process number

By the way, at the time of Context Switching, the corresponding CPU cannot do anything. Therefore, if Context switching is performed frequently, overhead will occur and efficiency (performance) will drop.

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

What is a Context Switch?
What is a distribution?
What is a terminal?
What is a hacker?
What is a pointer?
What is a decision tree?
What is a super user?
What is a system call
[Definition] What is a framework?
What is a callback function?
What is a python map?
[Python] What is a zip function?
[Python] What is a with statement?
What is a lexical scope / dynamic scope?
What is namespace
What is copy.copy ()
What is Django? .. ..
What is POSIX?
What is Linux
What is klass?
What is SALOME?
What is a dog? Django installation volume
What is a dog? Python installation volume
What is Linux?
What is python
What is hyperopt?
What is Linux
What is pyvenv
What is __call__
What is Linux
What is Python
What is a dog? Django--Create a custom user model
What is a dog? Challenge Django templates! Volume
It's a Mac. What is the Linux command Linux?
What is a dog? Django--Create a custom user model 2
Tell me what a conformal map is, Python!
What is Piotroski's F-Score?
What is Raspberry Pi?
[Python] What is Pipeline ...
What is Calmar Ratio?
[PyTorch Tutorial ①] What is PyTorch?
What is hyperparameter tuning?
What is JSON? .. [Note]
What is Linux for?
What is ensemble learning?
What is TCP / IP?
What is Python's __init__.py?
What is an iterator?
What is UNIT-V Linux?
[Python] What is virtualenv
What is machine learning?
What is a dog? Django App Creation Start Volume--startapp
What is a dog? Django App Creation Start Volume--startproject
Basics of Python learning ~ What is a string literal? ~
What is a recommend engine? Summary of the types
What is God? Make a simple chatbot with python
To myself as a Django beginner (2) --What is MTV?
What is Minisum or Minimax?
What is Linux? [Command list]
What is the activation function?
What is the Linux kernel?