OS & Hardware

During a context switch, what must be saved for the process being switched out?

  1. AThe contents of the disk files the process is using
  2. BCPU execution state such as register values and the program counter
  3. CThe entire contents of the process's physical memory
Show answer and explanation

Answer: B. CPU execution state such as register values and the program counter

A context switch saves CPU state, such as general registers, the program counter, the stack pointer and the operating mode, so the process can later resume exactly where it left off, and loads the state of the next process. When switching processes, the register pointing to the page table is also switched. Memory and file contents remain in place, so they need not be saved on each switch.

  • A. File contents remain on disk unchanged.
  • B. Correct. The CPU state needed to resume is saved.
  • C. Memory contents stay in place and are not saved on each switch.
Practice this topic Back to topic

More OS & Hardware questions

  1. Why can a process context switch degrade performance more than the time spent saving and restoring registers would suggest?
  2. What is the advantage of tagging each TLB entry with an ASID (address space identifier)?
  3. What mechanism mainly lets the OS reclaim the CPU at regular intervals, even from programs that never give it up voluntarily, and switch to other processes?
  4. When reading a device status register via memory-mapped I/O as above, why is it declared volatile and the region configured as uncached?
  5. When is polling, in which the CPU repeatedly checks device status instead of using interrupts, advantageous?