OS, networking and concurrency · Question 29 of 50

What is the difference between a process and a thread?

What they're checking

The fundamentals, and how Node.js fits in.

The answer

A process is a running program with its own memory, isolated by the operating system: one crashing does not corrupt another, but starting one and talking between processes costs more. Threads live inside a process and share its memory, so they are cheaper to create and can share data directly, but they need locks to avoid race conditions, and one bad thread can take the whole process down.

Node.js runs your JavaScript on one main thread with an event loop, uses a small thread pool (libuv) for some I/O, and offers worker threads for CPU-heavy work. Chrome runs each site in its own process, so one tab cannot read another's memory.

The picture

process A [ memory │ thread 1, thread 2 ]    process B [ memory │ thread 1 ]
          shared inside: needs locks            isolated from A: talks by IPC
The follow-up they'll ask

Concurrency or parallelism?

Show the answer

Concurrency is handling many things at once by interleaving them; parallelism is doing several at the same instant on several cores. Node's event loop is concurrent without being parallel.

Your progress stays on this device.