ZZomato·Tech KnowledgeL3DSA Round

Difference Between a Process and a Thread

Problem What is the difference between a process and a thread? Give a real-world example of an application of threads.

Be ready to discuss

  • Process: an independent execution unit with its own virtual address space, file descriptors, and resources, isolated by the OS so a crash in one does not corrupt another.
  • Thread: a lightweight execution unit inside a process, sharing the heap, code, and open files with sibling threads while keeping its own stack, registers, and program counter.
  • Cost: thread context switches are cheaper because the address space and page tables stay mapped — no TLB flush — whereas process switches are heavier; thread creation is likewise cheaper.
  • Consequence of sharing: shared memory makes communication trivial but demands synchronization (mutexes, atomics) to avoid race conditions and deadlocks; processes need explicit IPC (pipes, sockets, shared memory segments) but get isolation for free.
  • Real-world example: a web browser running UI rendering, network fetches, and JavaScript execution on separate threads in one process — plus the modern twist that browsers use separate processes per tab precisely to regain isolation.
  • Trade-off framing: choose threads for shared-state, low-latency concurrency; choose processes for fault isolation and security boundaries.
  • Related ground: user-level threads versus kernel threads, thread pools and why unbounded thread creation fails, and how green threads/goroutines/async runtimes multiplex many logical tasks onto few OS threads.
asked …
LeaderboardSalaryAccount