ITPEC FE Morning April 2018 Question 19

Topic: SoftwareAlso asked in Spring 2021

For a multiprogramming switching procedure of processes shown in the figure below, which of the following is an appropriate combination of OS processing for A through C?

State of process IOS processingState of process IIInterruptRunningstateReadystateReadystateRunningstateABC
OptionABC

Explanation

Save, select, restore — the OS first saves the interrupted process's state, then chooses the next process, then restores that process's state.

When the interrupt stops process I, the OS saves its register contents and program counter in its process control block (A). The scheduler then picks a process from the ready queue, here process II (B). Finally the dispatcher loads process II's saved state into the CPU (C), and process II runs from where it left off, while process I waits in the ready state.

Answer (c)

Why not others:

  • •(a) — restoring first would overwrite process I's registers before they are saved, and no process has been selected to restore yet
  • •(b) — the OS cannot restore a running state before it has selected which process's state to restore
  • •(d) — restoring process II's state before saving process I's would destroy process I's register contents, so it could not resume later

Key rule: A context switch always saves the old state first and restores the new one last; the scheduling decision sits between them.

Software · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.