What is a context switch in an operating system?
a) Changing from user mode to kernel mode
b) Switching between different processes
c) Saving the state of a process and loading another
d) Changing the state of the CPU
Answer:
c) Saving the state of a process and loading another
Explanation:
A context switch is the process of saving the state of a currently running process and loading the state of another process. This allows the operating system to switch between multiple processes efficiently and manage CPU time for each process.
The OS stores the state of the current process (such as registers, program counter, and memory allocation) in its Process Control Block (PCB), then loads the state of the next process to resume its execution.
Context switching is essential for multitasking systems, as it allows multiple processes to run seemingly simultaneously by quickly switching between them, giving each a fair share of CPU time.