LearnThatStack Ace your next interview
Operating Systems · question
Question 3 of 56

What is the difference between a process and a thread?

beginner
← All Operating Systems questions
Re-explain
Visual ↓

The core difference is memory sharing. A process owns a private address space. Threads live inside one process and share that space, including the heap and global data.

Because threads share memory, they can pass data by reading and writing the same variables. Two processes cannot, so they need pipes, sockets or shared-memory setups. Each thread still gets its own stack and registers, so it can run its own function calls independently.

The tradeoff is safety versus speed. Shared memory makes thread communication fast but risky, since one thread's bad write can corrupt another's data. Separate processes stay isolated, so a crash in one usually leaves the others running. Pick threads for tight cooperation and processes for isolation.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Operating Systems One question at a time. Answer out loud, get graded, see what you missed.
See it - interactive diagram
What two threads share and two processes do not
Before any writecounter = 0; // in each process
Stacks
thread 1: p1
thread 2: p1
process B: p2
process C: p3
Heap + globals
1process A
counter0
2process B
counter0
3process C
counter0

Process A runs two threads. Each has its own stack and registers, but both share one counter. Processes B and C keep one counter each.

Thread 1 writes*p = 7; // thread 1
Stacks
thread 1: p1
thread 2: p1
process B: p2
process C: p3
Heap + globals
1process A
counterchanged7
2process B
counter0
3process C
counter0

Both threads use one counter, so thread 2 reads 7 too. A bad write reaches thread 2 the same way.

Process B writes*p = 9; // process B
Stacks
thread 1: p1
thread 2: p1
process B: p2
process C: p3
Heap + globals
1process A
counter7
2process B
counterchanged9
3process C
counter0

The 9 stays inside process B, so process C still reads 0. Sharing it takes a pipe, a socket or shared memory.

Threads have separate stacks but share the heap, so one write reaches both. Processes keep private memory and share data through a pipe, a socket or shared memory.

© LearnThatStack - diagrams may not be republished without permission.

Other questions have diagrams like this too. Sign in to ask for one where it's missing - it's free.

Create a free account
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • Why is creating a thread cheaper than creating a whole new process? No new address space or page tables to build. A new thread needs its own stack, registers and a kernel entry, not much else.
  • Two threads each increment a shared counter a million times. Why can the total come out short? Name the race. Read-modify-write on the counter isn't atomic, so updates get lost. Fix it with a mutex or an atomic increment.
  • Is switching between two threads of one process cheaper than switching between two processes? Same address space, so the page tables stay put and cached translations stay valid. Registers and the stack pointer still get swapped.
  • Why might a browser put each tab in its own process instead of a thread? Isolation. A crash or bad write in one tab stays in that tab. The cost is more memory and explicit IPC instead of shared variables.
  • If processes don't share memory, how do they exchange data? Name pipes, sockets and shared memory, and say which ones copy data through the kernel and which one needs setup and its own locking.

What you can say

  1. The core difference is that a process owns a private address space, while threads inside one process share that space.
  2. That shared space includes the heap and global data, so threads can pass data just by reading and writing the same variables.
  3. Each thread still gets its own stack and registers, which is what lets it run its own function calls independently.
  4. Two processes can't see each other's memory, so they talk through pipes, sockets or a shared-memory region they set up on purpose.
  5. The tradeoff is speed versus safety, because one thread's bad write can corrupt another's data, while a crashed process usually leaves the others running.
  6. So I'd pick threads when the work needs tight cooperation, and processes when I need isolation.

Weak answers to avoid

  • Says "a thread is a lightweight process" and stops That's a slogan, not a difference. Say what threads share, the heap and globals, and what each one keeps for itself, its stack and registers.
  • Thinks threads share their stacks too Each thread gets its own stack and registers, and that's how it runs its own call chain. Leaving it out suggests you don't know how threads execute.
  • Calls threads strictly better because they're faster Shared memory means one bad write can corrupt everyone's data. Name that cost and say when you'd use processes for isolation.
  • Never says how processes communicate Once you say processes don't share memory, the interviewer expects to hear how data gets between them. Name pipes, sockets or shared memory.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Operating Systems cheatsheet.

← Back to all Operating Systems questions
Pro · $10/mo

49 of 56 Operating Systems answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime