Learning outcomes
- Contrast multiprocess and multithreaded systems and discuss their use cases.
Differentiate clearly between multiprocess and multithreaded systems, and select an appropriate approach for common software scenarios.
These terms describe parallelism at different layers: multiprocess is about running multiple independent processes, while multithreaded is about multiple execution paths (threads) inside one process.:contentReference[oaicite:2]{index=2}
| Term | What it means | Layer |
|---|---|---|
| Multiprocess | OS manages multiple processes (multiple programs in execution) concurrently. | OS scheduler + separate address spaces |
| Multithreaded | One process contains multiple threads of execution working concurrently. | Application design + OS thread support |
A process is a program in execution, including program code, current activity (program counter and registers), stack, data section, and heap.:contentReference[oaicite:4]{index=4}
Because processes are isolated, they typically communicate using OS mechanisms such as message passing (pipes, queues, sockets) or shared memory segments.:contentReference[oaicite:8]{index=8}
Separate processes improve modularity and fault isolation: if one process crashes, others can continue.:contentReference[oaicite:9]{index=9}
A thread is the basic unit of CPU utilization. It has its own thread ID, program counter, register set, and stack, but shares the process’s code section, data section, and OS resources like open files and signals.
Because threads share memory, incorrect synchronization can cause race conditions and inconsistent data. (We cover synchronization properly in later units.)
| Feature | Multiprocess (Multiple Processes) | Multithreaded (Multiple Threads in One Process) |
|---|---|---|
| Memory | Separate address space per process (strong isolation).:contentReference[oaicite:14]{index=14} | Shared address space within a process; each thread has its own stack/PC/registers. |
| Communication | IPC required: pipes, sockets, message queues, shared memory, etc.:contentReference[oaicite:16]{index=16} | Direct shared variables (needs synchronization). |
| Context switch cost | Higher (process state + memory context).:contentReference[oaicite:18]{index=18} | Lower (thread state: registers/stack/PC). |
| Fault isolation | High: crash in one process usually does not kill others.:contentReference[oaicite:20]{index=20} | Lower: a serious bug in one thread can crash the whole process (shared memory). |
| Best for | Modular systems, strong isolation, security boundaries (services separated).:contentReference[oaicite:21]{index=21} | High responsiveness and shared-data parallel tasks within one application (browser, editors). |
Consider a busy web server that must handle many clients at the same time. A traditional approach is to create a separate process for each request, but a more efficient approach is to create threads within a single server process. The OS book explains that process-per-request was common before threads became popular.
If you need maximum isolation, prefer multiprocess design. If you need shared-data speed and responsiveness, prefer multithreading—provided synchronization is correct.