Skip to content
We areTOP 1%

What is the difference between a process and a thread?

EasyConceptProcesses & Threads
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

A process is a program in execution with its own memory space (code, data or global variables, heap and stack) and its own resources, such as open files. A thread is a lightweight unit of execution inside a process. Threads of the same process share its code, data, heap and open files, but each thread has its own stack, program counter (the address of the next instruction) and registers.

  • Isolation: processes are protected from each other, so one crashing does not affect another. A bug in one thread can crash the whole process.
  • Cost: creating a thread and switching between threads is cheaper, because the memory space (the page tables) does not have to change.
  • Communication: threads share memory directly, which is fast but needs locks; processes need inter-process communication (IPC) such as pipes or sockets.

Example: Google Chrome runs each tab in a separate process, so a crashing tab does not close the whole browser. Inside one tab's process, several threads share the same page data: the main thread runs JavaScript, while other threads compose and draw the page on screen.

More in Processes & Threads

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account