I have a problem set question where I was given the solution, but don’t quite understand the details.
The question is:
How do we context switch?
The answer is:
- Step 1: Save context of process A
- Step 2: Restore context of process B
- Step 3: Resume executing process B
I’m wondering what saving and restoring the context of process A and B means?
I was going to say save memory mapping of A, restore memory mapping of B before looking at the answer, but is there something more than the memory mapping to saving and restoring?
AFAIK the data that is saved is the so called PCB (Process Control Block). What exactly is stored and how it is stored depends on the OS. But usually beside the “memory mapping” a PCB also contains the register values (especially the instruction pointer), the pointer to the parent process, I/O information, etc.