Skip to main content
BeginnercomparisonReported frequent at Cognizant

What is the difference between a process and a thread?

ReportedSource: GeeksforGeeks interview experience: Microsoft SDE-I, 1+ year

Quick answer

Process: own address space and resources, isolated, heavier, needs IPC. Thread: runs inside a process sharing its memory, own stack/registers, cheaper, needs synchronisation.

Process. A running program with its own virtual address space, open files, and at least one thread. Processes are isolated: a crash or bad pointer in one does not corrupt another. Communication needs IPC (pipes, sockets, shared memory). Creating and switching processes is relatively expensive (new address space, TLB flush).

Thread. A unit of execution inside a process. Threads share the process's memory, heap and file descriptors but each has its own stack, registers and program counter. Creation and context switches are cheaper, and sharing data is easy, which also means data races unless you synchronise (locks, atomics).

Trade-offs.

  • Isolation and fault containment: processes (e.g. browsers run tabs as separate processes).
  • Low-latency sharing and lighter weight: threads (e.g. a web server thread pool).

Language notes. In CPython the GIL means CPU-bound threads do not run Python bytecode in parallel; use multiprocessing for CPU-bound work and threads for I/O-bound work.

Discussion