in Operating System retagged by
478 views
7 votes
7 votes

Consider the context switch of a CPU from the context of process P1 to that of process P2.

Consider the following two events in the chronological order of the events during the context switch:

  • E1: The stack pointer shifts from pointing to the kernel stack of $\mathrm{P} 1$ to the kernel stack of $\mathrm{P} 2$;
  • E2: The program counter shifts from pointing to an address in the memory allocated to $\mathrm{P} 1$ to an address in the memory allocated to P2.

Which of the following statements is/are true regarding the relative ordering of events E1 and E2?

  1. E1 occurs before E2.
  2. E2 occurs before E1.
  3. E1 and E2 occur simultaneously via an atomic hardware instruction.
  4. The relative ordering of E1 and E2 can vary from one context switch to the other.
in Operating System retagged by
478 views

1 Answer

3 votes
3 votes

Question Source: Q 16  https://www.cse.iitb.ac.in/~mythili/os/ps/xv6/ps-xv6-proc.pdf

The complete concept is already been discussed here - 

$$\begin{align*} & \text{Step A:} \\ & - \text{Saving the context of P1} \\ & - \text{Restoring the context of P2, which includes shifting} \\ & \quad \text{the stack pointer from P1's kernel stack to P2's} \\ & \quad \text{kernel stack.} \\ & \text{Step B:} \\ & - \text{Starting the execution of P2} \\ & - \text{Shifting the program counter to P2's address} \\ & \quad \text{space from P1's address space.} \end{align*}$$

Answer:

Related questions