educative.io

Educative

Context switching

In the timer interrupt handler, the OS decides to switch from running Process A to Process B. At that point, it calls the switch() routine, which carefully saves current register values (into the process structure of A), restores the registers of Process B (from its process structure entry), and then switches contexts , specifically by changing the stack pointer to use B’s kernel stack (and not A’s). Finally, the OS returns-from-trap, which restores B’s registers and starts running it.

In the above statement, how did the process structure entry for Process B get created? Was the process already running?
What happens when Process A switches to a newly spawned Process B? In this scenario also will process B already have a process structure entry?


Course: Operating Systems: Virtualization, Concurrency & Persistence - Learn Interactively
Lesson: Problem #2: Switching Between Processes - Operating Systems: Virtualization, Concurrency & Persistence

Hi @Harsh_Sharma,

No, the process B is not in a running state. Process B is waiting for its turn to run…
Yes, in the second scenario, process B have its process structure entry. It is created at the time of process creation.