:PROPERTIES:
:ID: 2f3155e9-a235-47f7-bc69-22471cc0f558
:mtime: 20240525073336 20240304110306
:ctime: 20240304110251
:END:
#+title: context switch
#+filetags: :public:project:
* Context switching
Switching the CPU to another process requires performing a state save of the current process and a state restore of a different process.
When a context switch occurs, the kernel saves the context of the old process in its [[id:6f77458f-4865-4da5-b6ac-691802b700df][process control block]],
loads the saved context of the new process scheduled to run.
Context-switch time is pure overhead, because the system does no useful work while switching.
Switching between processes means taking 2 steps
1) Saving the context of the currently
executing [[id:ea9ceb4e-ff99-4939-ad40-90d5dae2d567][process]] (if any), and
2) Restoring the context of the [[id:ea9ceb4e-ff99-4939-ad40-90d5dae2d567][process]] being
resumed