Appearance
1. Process vs Thread
Process — a program in execution, with its own isolated memory space, resources, and state. Each process gets its own code, data, heap, and stack; its own file descriptors, registers, and PC; and isolation from other processes (one crash doesn't crash others).
Thread — a unit of execution within a process — lightweight, shares the parent process's memory. Each thread has its own stack + registers + PC, but shares the heap, code segment, global data, and file descriptors with its sibling threads.
| Aspect Process Thread | ||
|---|---|---|
| Memory | Separate address space | Shared address space |
| Creation cost | Heavy (fork/exec) | Light |
| Communication | IPC (pipes, sockets, shared mem) | Direct (shared memory) |
| Isolation | Strong — crash is contained | Weak — one bad thread can kill all |
| Context switch | Expensive | Cheap |
| Example | Chrome tabs (separate processes) | Chrome's JS engine threads |
Why it matters: processes give you isolation (browser tabs, microservices); threads give you parallelism with shared data (web server handling requests, a game engine's physics + rendering).
Analogy: a process is a factory — its own building, equipment, workers. A thread is a worker inside that factory — workers share the floor and tools but each does their own task.