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.
› 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.
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.
Processes buy fault isolation at high memory and IPC cost; threads buy cheap sharing and zero-copy speed with no crash containment.