4.2.4 · D3Operating Systems

Worked examples — Processes — PCB, states (new - ready - running - blocked - terminated)

2,734 words12 min readBack to topic

Before symbols: a quick reminder of the alphabet we use.


The scenario matrix

Think of every process story as a choice of "cell" from this table. Each column is a kind of thing that can happen; each row is a case class we must cover so the reader never meets an unshown scenario.

Cell Case class What triggers it The transition it exercises
C1 Plain CPU-only run never asks for I/O, short enough to finish in one slice New→Ready→Running→Terminated
C2 Preemption (timeout) slice ends before the job finishes Running→Ready (not Blocked!)
C3 I/O wait + wake-up process calls a slow device Running→Blocked→Ready→Running
C4 Higher-priority arrival a more urgent process appears Running→Ready (preempt by priority)
C5 Degenerate: never runs killed while still Ready / never dispatched New→Ready→Terminated
C6 Degenerate: killed mid-run crash / kill signal while Running Running→Terminated
C7 Limiting: pure I/O-bound almost always Blocked, barely uses CPU Blocked ⇄ Ready loop
C8 Real-world word problem a download-and-save app mixes C3 + C1
C9 Exam twist "Blocked→Running?" style trap tests the golden rule
C10 Zero-work / instant exit process that does nothing New→Ready→Running→Terminated in a blink

The ten worked examples below hit every cell. Each is tagged with its cell number.


Reading a state timeline

Every geometric example on this page uses one picture format. Meet it once so the rest are instant.

Figure — Processes — PCB, states (new - ready - running - blocked - terminated)

The worked examples

Example 1 — Plain CPU-only run (C1)


Example 2 — Preemption by timeout (C2)

Figure — Processes — PCB, states (new - ready - running - blocked - terminated)

Example 3 — I/O wait and wake-up (C3)

Figure — Processes — PCB, states (new - ready - running - blocked - terminated)

Example 4 — Higher-priority arrival preempts (C4)


Example 5 — Degenerate: process killed while still Ready (C5)


Example 6 — Degenerate: killed mid-run (C6)


Example 7 — Limiting case: a pure I/O-bound process (C7)


Example 8 — Real-world word problem: download-and-save app (C8)


Example 9 — Exam twist: "Blocked → Running" trap (C9)


Example 10 — Zero-work / instant-exit process (C10)


Recall Which cell did each example hit?

Example 1 hits which case class? ::: C1 — plain CPU-only run. Example 2? ::: C2 — preemption by timeout (→ Ready). Example 3? ::: C3 — I/O wait and wake-up. Example 4? ::: C4 — higher-priority arrival preempts. Example 5? ::: C5 — killed while still Ready (Running skipped). Example 6? ::: C6 — killed mid-run (Running → Terminated). Example 7? ::: C7 — pure I/O-bound limiting case. Example 8? ::: C8 — real-world download-and-save word problem. Example 9? ::: C9 — the Blocked→Running exam trap. Example 10? ::: C10 — zero-work instant-exit process.


Active Recall

Which transition does a time-slice timeout cause?
Running → Ready (never Running → Blocked).
When I/O completes, where does a Blocked process go?
To Ready — it must re-queue; Blocked never jumps to Running.
Can a process reach Terminated without ever being Running?
Yes — e.g. killed while Ready (New → Ready → Terminated).
For a pure I/O-bound process, which state dominates its time?
Blocked (Running is a tiny fraction, ~1% in Example 7).
Why is wall-clock time larger than CPU time in Example 3?
Because of the Blocked stretch waiting on the disk — I/O wait is not CPU time.
In preemptive priority scheduling, what state does the out-ranked running process enter?
Ready (it can still run, it was only out-prioritised).