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
| Question | Example | |
|---|---|---|
| Mechanism | How? | Context switch — stop one process, start another |
| Policy | Which? | 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 — 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:
| Piece | Role |
|---|---|
| Address space | Code, static data, heap, stack in memory |
| Registers | Including PC (next instruction) and stack/frame pointers |
| I/O info | Open files, etc. |
Process creation (high level)
- Load code + static data into the address space (eagerly in simple OSes; lazily with paging in modern ones)
- Allocate and initialize the stack (locals, args for
main) - Allocate a small heap (grows via
malloc/ OS) - Set up default I/O (e.g. stdin / stdout / stderr on UNIX)
- Jump to
mainand transfer the CPU to the new process
Rank the sequence
1 / 1Order the steps the OS takes to create and start a process.
OrderDrag the handle to rearrange — top should be first.
- 1Allocate and initialize the stack
- 2Load code and static data into the address space
- 3Jump to main and transfer the CPU to the new process
- 4Allocate a small heap
- 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:
| State | Meaning |
|---|---|
| Running | Currently executing on a CPU |
| Ready | Runnable, but the OS chose someone else |
| Blocked | Waiting 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).
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.
Rank the sequence
1 / 1A 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.
- 1Blocked (waiting for the I/O)
- 2Running (executes, then issues I/O)
- 3Ready (again, after I/O completes)
- 4Ready (initial)
Drag items into the correct order (or use ↑↓), then check.
Check your understanding
Processes and CPU virtualization
1 / 4Time 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.
Homework: process-run.py
0/8 startedData 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
| Term | Meaning |
|---|---|
| Process | Running program + machine state |
| Time sharing | Alternate CPU use → virtual CPUs |
| Mechanism / policy | How to switch vs which to run |
| Running / Ready / Blocked | Core states + I/O and schedule transitions |
| PCB / process list | OS bookkeeping for every process |
Next: Process API — fork, exec, wait, and how shells use them.
Further Reading
- Remzi & Andrea Arpaci-Dusseau — Operating Systems: Three Easy Pieces Ch. 4
- xv6 — process structures in
proc.h/proc.c