Search code examples
operating-systemcpucontext-switchcontext-switching

Why is the context not saved in the process itself instead of the PCB?


I have read that when a context switch happens, the context of that particular process will be saved in the process control block. But I wonder why the context couldn't be saved in the process itself so the CPU only had to remind itself which process it had to resume instead of making a copy of the context to the PCB.


Solution

  • The context is saved in the Process CONTEXT Block. The state of a process is defined by the values in the process's registers. What you are suggesting would require having a separate set of registers for each process which would make hardware design a nightmare.

    The CPU is only aware of the currently running process. If the Process Context Block were in the user address space of the process, its values would be inaccessible.