TRT
Sign in

Process vs Thread at a Glance

Visual comparison of processes and threads: memory isolation, creation cost, communication, and failure boundaries.

The Runtime Theory Team05 stages

trace / request.md

PROCESSTHREADMEMORY ISOLATIONCREATION COSTCOMMUNICATION

readyAn independent program with its own memory space, file descriptors, and kernel state. Created via fork(). Memory isolation is hardware-enforced by the MMU.

Process vs Thread at a Glance

This diagram compares processes and threads across five dimensions.

Quick Reference

DimensionProcessThread
MemorySeparate address spaceShared address space
Creationfork() / exec() — expensiveclone() — cheap
CommunicationIPC (pipes, shared memory)Shared variables (needs locks)
Crash impactIsolated — others surviveAll threads in the process crash
OS overheadPCB + page tables per processOnly a stack + TCB per thread

Read: What Is a Process? · [Interview: Process vs Thread]

Stage-by-stage execution walkthrough

This request flow decomposes Process vs Thread at a Glance into 5 sequential stages so you can trace where latency accumulates, which state transitions are irreversible, and where production failure modes occur.

Stage 1: Process

An independent program with its own memory space, file descriptors, and kernel state. Created via fork(). Memory isolation is hardware-enforced by the MMU. During this transition, the runtime enforces strict state invariants before handing control to the next stage: inputs are validated at the boundary, state mutations are ordered deterministically, and latency/resource costs are bounded so downstream consumers never observe a torn or partially initialized state.

Stage 2: Thread

A lightweight execution unit sharing its parent's memory space and file descriptors. Created via clone() or pthread_create(). Shares everything except the stack. During this transition, the runtime enforces strict state invariants before handing control to the next stage: inputs are validated at the boundary, state mutations are ordered deterministically, and latency/resource costs are bounded so downstream consumers never observe a torn or partially initialized state.

Stage 3: Memory Isolation

Process memory is isolated — one crashing cannot corrupt another's memory. Thread memory is shared — a buffer overflow in one thread can crash all threads in the process. During this transition, the runtime enforces strict state invariants before handing control to the next stage: inputs are validated at the boundary, state mutations are ordered deterministically, and latency/resource costs are bounded so downstream consumers never observe a torn or partially initialized state.

Stage 4: Creation Cost

Process creation is expensive: allocate PCB, copy/inherit page tables, duplicate file descriptors. Thread creation is cheaper: allocate a stack (~8MB) and a small TCB (~few hundred bytes). During this transition, the runtime enforces strict state invariants before handing control to the next stage: inputs are validated at the boundary, state mutations are ordered deterministically, and latency/resource costs are bounded so downstream consumers never observe a torn or partially initialized state.

Stage 5: Communication

Processes communicate via IPC (pipes, shared memory, message queues, signals). Threads communicate by sharing variables — faster but requires locks, mutexes, and semaphores. During this transition, the runtime enforces strict state invariants before handing control to the next stage: inputs are validated at the boundary, state mutations are ordered deterministically, and latency/resource costs are bounded so downstream consumers never observe a torn or partially initialized state.

Production invariants and failure modes

Processes trade creation overhead for failure isolation. Threads trade isolation for speed and shared-memory concurrency. Choose processes when isolation matters, threads when shared state and low creation cost matter. When debugging or capacity-planning this flow in production, instrument each stage boundary separately (measuring both p50 median and p99.9 tail latency), verify what happens when an intermediate stage times out or drops packets, and ensure retry or fallback paths preserve end-to-end idempotency.

Not started

Sign in to save your learning progress.

Sign in to save