Processes and threads: isolation versus sharing
What is the difference between a process and a thread? When would you choose one over the other?
what they're testing: The interviewer is probing whether you can reason about execution, resource sharing, isolation, and the trade-offs they create.
A process is an isolated execution environment, while a thread is one flow of execution inside a process. A process has an address space and operating-system resources, plus at least one thread. The operating system schedules threads to run. Threads in the same process share its address space and resources such as open files, but each thread has its own stack, registers, and thread-local state.
Threads are generally cheaper to create and switch between than processes, and shared memory makes communication fast. The trade-off is coordination: unsynchronized access to mutable data can cause races, while poorly designed locking can deadlock. A serious fault in one thread may terminate the entire process. Separate processes normally have separate address spaces and communicate through IPC such as pipes, sockets, or shared-memory mappings. They cost more but provide stronger fault and resource isolation. Separate privileges or sandboxing can add a security boundary.
Concurrency does not guarantee parallelism. Threads or processes can take turns on one core, or run at the same time on multiple cores. Choose threads for tightly coupled work that needs frequent, low-cost data sharing. Choose processes when failure isolation, independent lifetimes, or different privileges matter more.
Where people slip
the tempting wrong answer, and what's actually true
A thread is just a smaller program with its own address space.
A thread is a flow of execution inside a process. Threads in that process normally share its address space and resources.
Threads share everything, including their stacks and registers.
Threads share the process's address space and many resources, but each thread has its own stack, registers, identifier, and scheduling state.
Processes can never share memory.
Processes normally have separate address spaces, but operating systems provide explicit shared-memory mechanisms for inter-process communication.
Using multiple threads guarantees that code runs in parallel.
Threads may only run concurrently through time slicing, and parallel execution depends on available cores and scheduling.
If they push further
Why do shared-memory threads need synchronization?
Operations from different threads can interleave while accessing the same mutable state, causing data races or lost updates. Locks, atomic operations, or designs that avoid shared mutation provide safe coordination.
How do separate processes communicate?
They use IPC such as pipes, sockets, or shared-memory mappings. The choice depends on data volume, latency, portability, and how much isolation must be preserved.
What happens during a context switch?
The system saves the running thread's execution context and restores another's. Switching to a thread in another process also changes the address-space context, so it generally costs more than switching between threads in one process.
Sources
- Microsoft Learn: About Processes and Threads ↗learn.microsoft.com
- Microsoft Learn: When to Use Multitasking ↗learn.microsoft.com
- POSIX.1-2024: Definitions of Processes and Threads ↗pubs.opengroup.org
- Microsoft Learn: File Mapping ↗learn.microsoft.com
- Linux man-pages: POSIX Threads ↗man7.org
- Microsoft Learn: Synchronizing Multiple Threads ↗learn.microsoft.com
Now answer it yourself.
Reading a strong answer is easy. Producing one under pressure is the skill the interview tests. Gapmap grades your answer against the same bar an interviewer would.
beta
The interviewer part is in the works.
The diagnostic, personal maps, and AI mock interviews are being finished right now. The notes stay free either way. Leave an email and you'll get the first-cohort invite, plus a month of Pro when it opens.