Join waitlist
Operating SystemsCommunity question

process vs thread - how to answer in interview

Asked by Rahul Yadav 25 days ago 3 answers 8 votes

my answer sounds like I'm reading from a textbook (because I am). how do you explain it so it sounds like you actually understand

3 answers

Pranav Bhat25 days agoMost voted8

I usually say: a process is a running program with its own memory. A thread runs inside a process, threads of the same process share the memory (heap, globals, open files) but each has its own stack and registers.

Then an example: a browser can run each tab as a separate process so one crashing doesn't kill the rest, and inside a tab different threads do rendering, network etc.

Then one tradeoff: threads are cheaper and share data easily, but that's also why you need locks.

Kavya Nair24 days ago3

they'll probably follow up with context switching and why a thread switch is cheaper. prepare that too

Rahul Yadav24 days ago

browser example is nice, using that

Related questions

Go deeper

Want the full explanation, not just an answer?

Structured lessons on DSA, core CS, Java and interview skills, each ending in a quiz so you know it stuck.