Interview Prep Zoneby CuriouserLabs

Question 1 of 5 · senior level

What is the difference between a process and a thread — beyond the one-line answer?

🎤 Say this first

A process is an isolation unit: its own virtual address space, file descriptor table, credentials — the OS's container for running a program. A thread is an execution unit inside a process: its own stack, registers and program counter, but sharing the address space and resources with sibling threads. Sharing is the whole trade: threads communicate through memory at zero cost but can corrupt each other; processes are crash- and fault-isolated but must use IPC. Every 'thread vs process' architecture decision is choosing a point on that isolation-vs-sharing dial.

The full picture

ProcessThread
Address spaceOwn (page tables per process)Shared with siblings
OwnsFDs, credentials, signal handlers, memoryStack, registers, PC, scheduling state
Creation costHeavier (new address space; fork+COW helps)Light (allocate stack + kernel object)
Failure blast radiusContained — kernel cleans up everythingOne bad thread can take down the whole process
CommunicationIPC: pipes, sockets, shared memory (explicit)Plain memory (fast, and racy)
  • The kernel actually schedules threads (tasks), not processes — a process is better thought of as a resource container whose threads are the schedulable things.
  • What's in the per-thread kernel state: kernel stack, saved registers, scheduling class/priority; what's per-process: page-table pointer, FD table, memory maps, limits.
  • Architecture echoes: Chrome's process-per-site (isolation over memory), nginx's worker processes vs a JVM's thread pool, and PostgreSQL's process-per-connection vs MySQL's thread-per-connection — all the same dial.
  • A JVM is one process; every Java Thread was (pre-virtual-threads) a 1:1 kernel thread inside it — which is why one OOM or segfault kills all of them together.

🔄 Likely follow-up questions

  • Why does one thread's segfault kill the whole process?
  • What exactly do container namespaces add to a plain process?
  • When would you pick multiple processes over threads in a new system?