5. Operating systemsProcesses vs threads
Processes vs threads
A process is a running program with its own private memory and resources, walled off from other processes by the operating system. A thread is one path of execution inside a process; a process can have many, and they all share its memory. Think of a process as a kitchen and threads as cooks in it: cooks in one kitchen can grab the same ingredients easily but can also get in each other’s way, while separate kitchens are safer but must pass things through the door. That’s the trade-off: threads are cheaper to create and switch between and share data directly, but a bug in one can corrupt the rest, while processes buy isolation with more overhead.
In this lesson: Address spaces as separate towers, with threads sharing one heap. A context-switch cost meter.