Skip to main content

Source: Operating Systems: Three Easy Pieces (OSTEP) — Chapter 4, Arpaci-Dusseau & Arpaci-Dusseau

The Process Abstraction

A program on disk is lifeless — a pile of instructions and maybe some static data. A process is that program running: the OS loads it, gives it an address space, and lets it execute. Your laptop seemingly runs dozens of processes at once even with a few CPUs. How?

Crux: how does the OS provide the illusion of many CPUs?

Answer: virtualize the CPU with time sharing — run one process, stop it, run another. The cost is performance: each process may run slower when the CPU is shared.

Mechanisms vs Policies​

QuestionExample
MechanismHow?Context switch — stop one process, start another
PolicyWhich?Scheduler — which ready process runs next

Separating them is a classic OS design rule: you can change the scheduling policy without rewriting the context-switch machinery.

Time sharing vs space sharing

Time sharing — take turns with a resource (CPU, network link).
Space sharing — divide the resource (disk blocks assigned to files).

What Is Process State?​

A process is summarized by its machine state — everything it can read or update while running:

PieceRole
Address spaceCode, static data, heap, stack in memory
RegistersIncluding PC (next instruction) and stack/frame pointers
I/O infoOpen files, etc.

Process creation (high level)​

  1. Load code + static data into the address space (eagerly in simple OSes; lazily with paging in modern ones)
  2. Allocate and initialize the stack (locals, args for main)
  3. Allocate a small heap (grows via malloc / OS)
  4. Set up default I/O (e.g. stdin / stdout / stderr on UNIX)
  5. Jump to main and transfer the CPU to the new process
Quiz

Rank the sequence

1 / 1

Order the steps the OS takes to create and start a process.

OrderDrag the handle to rearrange — top should be first.

  1. 1Allocate and initialize the stack
  2. 2Load code and static data into the address space
  3. 3Jump to main and transfer the CPU to the new process
  4. 4Allocate a small heap
  5. 5Set up default I/O (stdin/stdout/stderr)

Drag items into the correct order (or use ↑↓), then check.

Process API (ideas every OS exposes)​

  • Create — start a program (shell command, double-click)
  • Destroy — kill a runaway process
  • Wait — block until a process finishes
  • Control — suspend / resume
  • Status — runtime, current state, …

Process States​

In the simplified model:

StateMeaning
RunningCurrently executing on a CPU
ReadyRunnable, but the OS chose someone else
BlockedWaiting for an event (e.g. disk I/O) — cannot run until that event

Transitions:

  • Scheduled: Ready → Running
  • Descheduled: Running → Ready
  • I/O initiate: Running → Blocked
  • I/O done: Blocked → Ready

Extra states in real systems (xv6 and UNIX): EMBRYO / creating, ZOMBIE (exited but not yet wait()ed by the parent).

Interactive: state transitions over time​

Step through two classic traces from OSTEP: CPU-only processes vs a process that blocks on I/O so another can run.

Try:

  • CPU only — Process0 runs to completion, then Process1. CPU stays busy.
  • CPU + I/O — when Process0 blocks, Process1 runs. When I/O completes, Process0 becomes Ready — the scheduler may keep Process1 running (a policy choice).
Key Insight

Blocking on I/O is what lets the OS keep the CPU useful. Without switching on I/O wait, the CPU would sit idle while the disk works.

Quiz

Rank the sequence

1 / 1

A process starts Ready, gets scheduled, issues an I/O request, and the I/O later completes. Order the states it passes through (its first state first).

OrderDrag the handle to rearrange — top should be first.

  1. 1Blocked (waiting for the I/O)
  2. 2Running (executes, then issues I/O)
  3. 3Ready (again, after I/O completes)
  4. 4Ready (initial)

Drag items into the correct order (or use ↑↓), then check.

Check your understanding​

Quiz

Processes and CPU virtualization

1 / 4

Time sharing the CPU primarily creates…

Pick an answer to see if you are right.

Coding challenges​

Same ideas as process-run.py, in miniature — Python to match that homework’s language.

Homework lab: process-run.py​

Grab the OSTEP CPU scheduling homework (process-run.py). Predict each answer before peeking with -c / -p. Use the lab below for notes and screenshots — everything is stored in this browser only (IndexedDB), including pasted images.

Lab

Homework: process-run.py

0/8 started

Loading lab…

Data structures: the process list​

The OS tracks every process in a process list (task list). Each entry is a PCB (process control block / process descriptor): pid, state, parent, open files, and a saved register context (so a stopped process can be resumed). xv6’s struct proc and struct context are the textbook picture of this.

When a process exits, it may sit in zombie until the parent wait()s — then the OS frees the PCB.

Summary​

TermMeaning
ProcessRunning program + machine state
Time sharingAlternate CPU use → virtual CPUs
Mechanism / policyHow to switch vs which to run
Running / Ready / BlockedCore states + I/O and schedule transitions
PCB / process listOS bookkeeping for every process

Next: Process API — fork, exec, wait, and how shells use them.

Further Reading​