Skip to content

Chapter 8: Process Context — Who's Running Your Code

Vol 3: Computer Core Expedition · Chapter 8


Metadata Card

AttributeValue
KeywordsProcess State Machine, Context Switching, Scheduling, PCB, fork/exec

Your Progress

"A program on disk is inert. When you run it, the OS creates a process — an active entity with its own address space, file descriptors, and execution state."


Encounter 1: Process States

New → Ready → Running → Terminated
           ↕        ↓
         Waiting ← I/O

Encounter 2: PCB (Process Control Block)

Each process has a PCB containing:

  • Process ID (PID)
  • Register state (for context switching)
  • Memory management info
  • Open file descriptors
  • Scheduling priority

Encounter 3: Context Switching

When the OS switches from one process to another:

  1. Save current process's registers to its PCB
  2. Load next process's registers from its PCB
  3. Flush TLB (if page tables differ)
  4. Resume execution of new process

Cost: 1-100 μs (thousands of CPU cycles)

Encounter 4: fork() and exec()

  • fork(): Creates a near-identical copy of the current process
  • exec(): Replaces the current process's memory with a new program

Verification Checklist

  • [ ] Can explain the process state machine
  • [ ] Can describe what happens during a context switch
  • [ ] Can explain the difference between fork() and exec()

Next Stop Preview

Chapter 9: Threads and Synchronization

Built with VitePress | Software Systems Atlas