Home/Labs/Processes vs Threads Memory Lab
All 280 Labs
INTERACTIVE LAB🧬

Processes vs Threads Lab (Interactive)

Spawn workers as processes or threads and compare RAM, spawn cost, sharing, and crash blast radius. Isolated virtual address spaces versus a shared heap: mutate memory, crash a worker, and watch which siblings survive under each model.

Processes vs Threads & Address Space Simulator

Compare isolated virtual address spaces against a shared heap: memory cost, spawn cost, IPC, and crash blast radius.

4 workers
Process PID 1042RUNNING
Private heap (MMU-isolated)val = 100
45 MB RSS: own page tables, FD table, runtime
Process PID 1559RUNNING
Private heap (MMU-isolated)val = 100
45 MB RSS: own page tables, FD table, runtime
Process PID 2076RUNNING
Private heap (MMU-isolated)val = 100
45 MB RSS: own page tables, FD table, runtime
Process PID 2593RUNNING
Private heap (MMU-isolated)val = 100
45 MB RSS: own page tables, FD table, runtime
Total RAM footprint
180 MB
Spawn cost (all workers)
10.00 ms
Live workers
4 / 4
Data sharing
IPC only
ISOLATION: Total: MMU page tables isolate every address spaceSHARING: IPC syscall + serialization (~300 μs per message)

› Initialized execution context.

How It Works Under the Hood

A process owns a virtual address space enforced by the MMU, so a segfault only reaps that process — but fork/exec costs milliseconds and every process duplicates its runtime (PostgreSQL, Chrome, Nginx). Threads share the heap, file descriptors, and globals with private stacks, spawning in tens of microseconds with zero-copy sharing, yet one unrecovered panic terminates every sibling. IPC (Unix sockets, pipes, shared memory) is the tax processes pay to collaborate.

Core Architectural Principles

  • Processes: ~45 MB RSS and ~2.5 ms fork cost each, but total hardware-enforced crash isolation.
  • Threads: shared heap with ~2 MB private stacks and ~25 μs spawn, but a single panic kills the whole process.
  • Cross-process data exchange requires kernel-mediated IPC instead of direct pointer access.
Interview Round Script

Answer "process or thread?" with the failure model: "Chrome uses one process per tab so a crashing script cannot take down the browser; MySQL uses thread-per-connection for memory efficiency." Cite PostgreSQL process-per-connection versus MySQL thread-per-connection when discussing database connection scaling.

Key Trade-Offs

Processes buy fault isolation at high memory and IPC cost; threads buy cheap sharing and zero-copy speed with no crash containment.

Related Curriculum Chapter

Processes vs Threads

Read Full Chapter Blueprint

Explore More Interactive Labs

View All 280 Labs