In revision.
Crisp5 min readGo deeper →

Processes vs threads

A process owns memory, threads share it. Pick by isolation needs, not by speed.

The answer

A process is an isolated address space with its own memory, file descriptors, and PID. A thread is an execution context inside a process that shares everything except its stack and registers. Creating a process on Linux costs roughly 1ms via fork+exec; creating a thread costs roughly 10us via clone. That two-order-of-magnitude gap is why every web server uses threads (or async) for request handling, not processes per request.

When to use which

Use processes when you need a crash in one unit to not take down the others. Chrome runs each tab in a separate process for exactly this reason. Postgres runs one process per connection so a bad query in one session cannot corrupt another. Pre-fork servers (Gunicorn, Unicorn) use processes to dodge the GIL in Python and Ruby.

Use threads when you need cheap concurrency with shared state and you trust the code. Java web servers, JVM apps, and C++ services all live here. Threads are also the default in any language where the runtime gives you safe concurrency (Go goroutines map onto OS threads via the runtime, Rust threads have compile-time data race prevention).

Cost breakdown

fork() on Linux:      ~1ms   (copy page tables, dup fds)
pthread_create:       ~10us  (clone(CLONE_VM | CLONE_FS | ...))
goroutine start:      ~1us   (user-space, 2KB stack)
async task spawn:     ~100ns (just a heap allocation)

A thread on Linux is literally a process that shares its address space. The clone() syscall with CLONE_VM flag is how pthread_create is implemented under the hood. There is no separate "thread" kernel object on Linux. This is why ps -eLf shows threads as schedulable entities.

Shared vs private

Threads share: heap, code, globals, file descriptors, signal handlers, current working directory.

Threads have private: stack, registers, thread-local storage, errno (via TLS).

Processes share nothing by default. To share memory between processes you need explicit IPC: shared memory segments (shm_open), pipes, sockets, or message queues.

Threads share heap inside a process. Processes are fully isolated.

The interview-grade answer

"Threads share memory and are cheap to create, around 10us. Processes are isolated and cost about 1ms. I reach for processes when I need crash isolation or to dodge a global interpreter lock, threads when I need to share state cheaply. For pure I/O concurrency I prefer async over either, because spawning a task is closer to 100ns and you avoid context-switch cost entirely."

Learn more