Concurrency FundamentalsThreads vs ProcessesEasy⏱️ ~2 min

What is a Process?

Definition
A process is a running program with its own private memory. No other process can see or touch this memory.

Think Of It Like Separate Apartments

Each process is like an apartment in a building. Your apartment has its own rooms, furniture, and stuff. Your neighbor cannot walk into your apartment and move your couch. The walls (enforced by hardware) keep everyone separate.

Process Memory Isolation
Process ACodeHeapStackWALLProcess BCodeHeapStackHardware-enforced isolation - no shared memory

Why Isolation Matters

Crashes stay contained: If your neighbor apartment catches fire, yours does not burn. Similarly, if one process crashes, others keep running. Your music player crashing does not kill your browser.

Security: A sketchy app cannot read your banking app memory. The walls between processes are real, enforced by the CPU itself.

The Cost of Separate Apartments

Moving in is expensive: Creating a new process takes 1-10 milliseconds. The OS must set up a whole new address space.

Talking to neighbors is slow: Since processes cannot share memory, they must communicate through the OS - pipes, sockets, files. This adds overhead.

Switching apartments takes time: When the CPU switches from one process to another, it takes 10-100 microseconds to swap all the memory mappings.

When To Use: Processes are best when you need safety and isolation - running untrusted code, separating security domains, or containing crashes.
💡 Key Takeaways
A process has private memory - like a separate apartment with walls
Crashes in one process do not affect others
Security: processes cannot read each other's memory (hardware enforced)
Cost: 1-10 ms to create, 10-100 μs to switch, slow communication
Best for: untrusted code, security separation, crash isolation
📌 Examples
1Chrome tabs: each tab is a separate process - one crash shows 'Aw Snap' but browser survives
2Web servers: worker processes handle requests - bad request kills one worker, not all
3Plugins: PDF readers run plugins in separate processes for security
← Back to Threads vs Processes Overview