# Threads vs processes

> Processes get separate address spaces; threads share memory inside one process and need care with races.

Source: https://fullbytedeveloper.com/blog/threads-vs-processes
Published here: 2026-12-03, updated 2026-12-03

A process is an isolated program image with its own private address space. Threads are lighter concurrent paths of control that usually share that same space inside one process [1] [2]. Pair those ideas with [Python multiprocessing vs threading](/blog/python-multiprocessing-vs-threading) plus [concurrency vs parallelism](/blog/concurrency-vs-parallelism-plain).

## Quick start: see two PIDs vs one address space idea

After `fork`, parent and child are separate processes [1]. A minimal C program is the textbook demo; from the shell you can still watch the pattern Bash uses daily:

```bash
/bin/sh -c 'echo parent=$$; ( echo child=$$ )'
```

On a draft Linux host:

```text
parent=12345
child=12346
```

Two different PID numbers mean two process entries in the kernel, even though the snippet was short [1]. For threads inside one process, `ps -L -o pid,tid,cmd -p $$` on a multithreaded program shows one PID and multiple thread IDs; run that against a real pthread program when you teach the distinction.

## Draw fork vs shared VM

<figure aria-label="Process fork versus thread shared address space">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 220" role="img" aria-hidden="true">
  <rect x="0" y="0" width="360" height="220" rx="12" fill="#0b1f3a"/>
  <text x="90" y="20" text-anchor="middle" font-size="12" font-weight="600" fill="#e6edf7" font-family="system-ui,sans-serif">fork() [1]</text>
  <text x="270" y="20" text-anchor="middle" font-size="12" font-weight="600" fill="#e6edf7" font-family="system-ui,sans-serif">clone + shared VM [2]</text>
  <rect x="25.7143" y="30" width="128.571" height="60" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="0.964286"/>
  <text x="90" y="58" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">parent PID 100</text>
  <text x="90" y="74" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">private VM map</text>
  <rect x="25.7143" y="104" width="128.571" height="60" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="0.964286"/>
  <text x="90" y="132" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">child PID 101</text>
  <text x="90" y="148" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">CoW after writes [1]</text>
  <rect x="205.714" y="30" width="128.571" height="60" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="1.28571"/>
  <text x="270" y="58" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">process PID 100</text>
  <text x="270" y="74" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">shared heap / globals</text>
  <rect x="205.714" y="104" width="61.7143" height="60" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="0.964286"/>
  <text x="236.571" y="132" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">thread A</text>
  <text x="236.571" y="148" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">own stack</text>
  <rect x="272.571" y="104" width="61.7143" height="60" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="0.964286"/>
  <text x="303.429" y="132" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">thread B</text>
  <text x="303.429" y="148" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">own stack</text>
  <line x1="270" y1="84" x2="236.571" y2="108" stroke="#14b8a6" stroke-width="0.642857"/>
  <line x1="270" y1="84" x2="303.429" y2="108" stroke="#14b8a6" stroke-width="0.642857"/>
  <text x="180" y="200" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">one bad write in shared VM affects every thread [2]</text>
</svg>
</figure>

`fork()` creates a child that starts as a duplicate of the parent [1]. Parent and child have separate memory spaces; at the moment of fork the contents match, but later writes and mappings in one do not affect the other [1]. The child receives a new process ID [1].

`clone()` creates a child with selectable sharing of address space, file table, signal handlers, and namespaces via flags [2]. Thread libraries typically share the virtual address space (`CLONE_VM` in common setups) so threads see the same heap while keeping separate stacks [2].

## Compare failure and communication

| Choice | Memory | Typical failure boundary | Talk to siblings |
|---|---|---|---|
| Process (`fork` + exec) | Separate VM [1] | One crash may not kill sibling | Pipes, sockets, shared mem APIs |
| Thread (shared VM) | Shared heap/globals [2] | One bad write corrupts all | Mutex, atomics, channels in lang |

Processes pay inter-process communication cost but gain isolation. Threads avoid marshaling large buffers but require synchronization for mutable shared state [2].

## Copy-on-write in plain words

Linux does not eagerly duplicate every page at `fork` [1]. Parent and child share read-only physical pages until one writes, then the kernel splits the mapping. That detail matters for memory accounting, not for security boundaries: logically they remain separate processes [1].

## Map into Python

CPython threads share one process and fight over the GIL; processes spawn interpreters. See [python-multiprocessing-vs-threading](/blog/python-multiprocessing-vs-threading). Pick threads for shared in-process caches with locks; pick processes when isolation or CPU parallelism in Python matters [1] [2].

## Map into shells and servers

Each command you start after Enter is usually a new process created via fork and exec, not a new thread inside Bash [5]. Web servers may use thread pools inside one process or worker processes; the table above is how you read their architecture diagrams.

For PID, credentials, and `/proc` vocabulary, see what is a process. For the Enter key path, see [what happens when you press Enter](/blog/what-happens-when-you-press-enter).

## Scheduling note

Linux schedules threads as tasks (`clone` children) and processes as tasks. From the kernel's view both are runnable entities with PIDs or TGIDs depending on setup [2]. Userland "thread" is mostly shared memory plus synchronization discipline.

## exec after fork in shells

`fork` alone duplicates the parent; `execve` replaces the child program image with `ls` or `python` [1] [2]. Bash follows that pattern for externals while keeping built-ins in-process [5]. Understanding exec explains why `type ls` shows a file path but `type cd` does not.

Environment and working directory are preserved across `fork` and adjustable before `exec` [2]. That is how pipelines and subshells inherit `PWD` and exported variables unless a subshell option says otherwise.

## Containers and namespaces (outline)

Modern Linux adds namespaces so a process can think it owns its own PID tree or network stack [2]. Containers bundle `clone` flags with cgroup limits. Threads versus processes still matter inside a container: one OOM in a threaded process kills the cgroup task group you scheduled together.

## When to choose which

Choose processes when you need fault isolation, separate privilege levels, or separate memory limits (cgroups). Choose threads when you share a large read-mostly dataset and synchronization is tractable. If neither fits, message-passing between processes (actor style) often beats a giant locked heap.

## Traps I still see

Spawning threads expecting crash isolation. One segfault in a thread can take the whole process [2].

Using processes to share a giant mutable in-memory structure without a shared-memory design. You will serialize or copy.

`fork` is free on a 64 GB parent RSS. Fork still triggers bookkeeping; respect CoW but measure.

Treating "multithreaded server" as automatically faster on CPU-bound Python.

Threads are always lighter than processes on Linux. Thread creation still involves kernel bookkeeping via `clone` [2].

Confusing green threads or async tasks with OS threads. Different layers.

## Signals and shared address space

A signal delivered to a threaded process can interrupt any thread unless masked [2]. Process-wide state such as signal dispositions is shared. That is one reason threaded programs isolate signal handling carefully while multi-process designs delegate signal policy per child [1].

Zombie children appear when a parent never collects exit status [1]. Bash usually waits on foreground jobs; background jobs need `wait` if scripts depend on exit codes [5].

## Kernel vocabulary shortlist

A task is schedulable. A thread group may share one PID in `top` while exposing multiple TIDs [2]. `getpid()` in C returns the thread group leader ID in many pthread programs. When documentation says "process," check whether it means OS process or pthread.

File descriptors are per-process; threads inside a process share the table [2]. One thread closing a descriptor races with another thread still reading unless you serialize access.

Measure resident set size separately for threaded and multi-process designs. Two processes each importing pandas pay import cost twice; two threads share one import at the cost of shared mutable risk [1] [2].

Run the PID demo, then read whether your runtime maps threads to `clone` with shared VM. Save one `ps -L` line in your notes when you teach fork versus pthreads so the diagram stays tied to real PIDs. [Concurrency vs parallelism](/blog/concurrency-vs-parallelism-plain) names overlap versus simultaneous CPU use on the CPU, while [Python multiprocessing vs threading](/blog/python-multiprocessing-vs-threading) shows how CPython maps those ideas onto interpreters and the GIL.

Send this to the friend who uses threads and processes as synonyms.

Image: Two panels comparing forked processes with separate address spaces versus threads sharing one heap with distinct stacks.
https://fullbytedeveloper.com/media/threads-vs-processes/threads-vs-processes-venice.webp
fork isolates memory; clone with shared VM is the usual thread shape on Linux.

## Sources

1. [Linux man-pages: fork(2), accessed 2026-12-03](https://man7.org/linux/man-pages/man2/fork.2.html)
2. [Linux man-pages: clone(2), accessed 2026-12-03](https://man7.org/linux/man-pages/man2/clone.2.html)
3. [Full Byte Developer: Python multiprocessing vs threading](https://fullbytedeveloper.com/blog/python-multiprocessing-vs-threading)
4. [Full Byte Developer: Concurrency vs parallelism plain](https://fullbytedeveloper.com/blog/concurrency-vs-parallelism-plain)
5. [Full Byte Developer: What happens when you press Enter](https://fullbytedeveloper.com/blog/what-happens-when-you-press-enter)
