Process vs thread
Two ways to run code at once — one isolated and safe, one shared and fast.
A process is a program with its own isolated memory and resources; a thread is a lighter unit of execution that lives inside a process and shares its memory. Processes are safer and crash-isolated but expensive to create and slow to communicate; threads are cheap and fast to talk between but a bug in one can corrupt or crash the whole process.
Isolated memory vs shared memory
Each process gets its own private virtual address space, so one process cannot read or corrupt another's memory — the OS enforces the wall. Threads within a process share that single address space, including the heap and global variables, so they can pass data by simply referencing it. This one difference — isolation versus sharing — drives every other trade-off between them.
Context-switch cost
Switching the CPU from one process to another is expensive: the OS must swap page tables and often flush TLB and cache state, because the memory mapping changes entirely. Switching between threads of the same process is lighter, since they share the address space and only the register set and stack pointer change. Thread switches are therefore cheaper and creation is faster, which is why threads are the default for fine-grained concurrency.
Communication
Because processes are isolated, they talk through explicit inter-process communication — pipes, sockets, message queues, or a deliberately shared-memory segment — all of which involve the kernel or serialization and cost time. Threads simply read and write the same variables, so communication is nearly free. That speed is a double-edged sword: shared mutable state means threads must guard it with locks to avoid races.
Crash isolation
A process is a fault boundary: if it segfaults or leaks, the OS reclaims it and other processes carry on untouched. A thread is not a boundary — an unhandled fault or memory corruption in one thread can bring down the entire process and every sibling thread with it. This is the core reliability reason to pay the price of separate processes.
Choosing between them
Reach for multiple processes when you want strong isolation and fault tolerance, or to sidestep limits like Python's global interpreter lock for CPU-bound work. Reach for threads when tasks are tightly coupled, need to share large data cheaply, and you can manage synchronization carefully. Many real systems combine both: a pool of processes, each running many threads.
Two units of execution
To run code concurrently, an operating system gives you two fundamental building blocks: the process and the thread. They are easy to blur together — both let a computer "do more than one thing at once" — but they sit at different levels and make opposite trade-offs, and knowing which to reach for is a staple of both interviews and real design.
A process is an instance of a running program with its own private, OS-protected slice of the machine: its own virtual address space, file descriptors, and other resources. A thread is a unit of execution *inside* a process — a single sequential flow of control with its own stack and registers, but sharing the process's memory and resources with its sibling threads. The one-line summary: a process is heavyweight and isolated, a thread is lightweight and shared. Every other difference between them falls out of that.
Memory: isolation versus sharing
The defining difference is memory. The OS gives each process its own virtual address space, and it enforces that boundary in hardware: process A physically cannot read or write process B's memory. This isolation is a feature — a bug in one program can't scribble on another's data — and it is why processes are the unit of protection on your machine.
Threads make the opposite choice. All threads within a process share that single address space: the same heap, the same global variables, the same open files. This makes sharing data between threads trivial and fast — you just reference the same object — but it also means threads can step on each other. Two threads writing the same variable without coordination produce a race condition, so shared mutable state must be guarded with locks, mutexes, or atomics. The convenience of sharing is exactly what creates the hardest class of concurrency bugs.
Cost: creation and context-switching
Because a process owns a full set of resources and a fresh address space, creating one is comparatively expensive, and so is switching the CPU between processes. A process context switch forces the OS to change the active memory mapping — swapping page tables and typically flushing the TLB and polluting caches — which is real overhead.
A thread is far cheaper on both counts. Creating a thread doesn't allocate a new address space, and a thread context switch within the same process only swaps registers and the stack pointer while leaving the memory mapping intact, so caches and the TLB stay warm. This is the core performance reason threads are the default tool for fine-grained concurrency: you can spin up many of them cheaply and switch between them quickly. (Runtimes push this further with user-space "green" or virtual threads that are lighter still than OS threads.)
Communication and crash isolation
The isolation that protects processes also makes them harder to coordinate. Since they can't see each other's memory, processes talk through inter-process communication (IPC): pipes, sockets, message queues, signals, or an explicitly requested shared-memory segment. All of these route through the kernel or require serializing data, so cross-process communication is slower and more ceremonious than the direct memory sharing threads enjoy.
The flip side is reliability. A process is a fault boundary: if it crashes — segfault, unhandled exception, out-of-memory — the OS tears it down and reclaims its resources while every other process keeps running. A thread is *not* a boundary. Because threads share everything, a memory corruption or fatal fault in one thread can take down the entire process and all its sibling threads at once. So there is a genuine tension: threads give you speed and easy sharing but concentrate risk, while processes give you containment at the cost of weight and slower communication.
Choosing, and how real systems combine them
The decision comes down to what you value for a given workload:
- Prefer multiple processes when you need strong isolation and fault tolerance (a crash in one worker shouldn't sink the service), when running untrusted or unstable code, or to bypass a runtime limit — the classic example being Python's Global Interpreter Lock, which prevents threads from executing Python bytecode in parallel, so CPU-bound Python scales with
multiprocessing, not threads. - Prefer threads when tasks are tightly coupled, need to share large in-memory data structures cheaply, and the concurrency is fine-grained enough that per-process overhead would dominate — provided you're disciplined about synchronization.
In practice mature systems layer both. A web server or database often runs a small pool of processes (one per core, for isolation and to use every core), and within each process a pool of threads (to handle many concurrent connections cheaply). The browser you're reading this in does the same, isolating tabs into separate processes for security and stability while using threads inside each for rendering, networking, and compositing. The art is matching the granularity of isolation to the failure modes and performance you actually need.
Process = an independent program instance with its own private address space and OS resources.
Thread = a lightweight execution path inside a process that shares the process's memory and resources.
Context-switching between processes is heavier (swap page tables, flush caches) than between threads.
Processes communicate via IPC (pipes, sockets, shared-memory segments); threads share memory directly.
Crash isolation: one crashing process doesn't take down others; one crashing thread can kill the whole process.
Use processes for isolation and fault tolerance; use threads for fast, memory-sharing concurrency within one task.
Quick quiz
Why is communication between threads faster than between processes?
What is the main reliability advantage of using separate processes?
Concurrency is not parallelism
Dealing with many things at once is a different idea from doing many things at once.
How computer memory works
A pyramid of trade-offs: the closer memory sits to the CPU, the faster, smaller and pricier it gets.
How Java virtual threads work
Millions of threads on a handful of OS threads — concurrency without the memory bill.
How Java works
Write once, run anywhere — the compile-to-bytecode-then-run-on-a-virtual-machine trick.