Operating Systems

Linux Process Model

Tasks, fork, clone, copy-on-write, namespaces, and cgroups as the real Unix.

Level: advanced

What is it?

Linux represents schedulable execution entities as tasks. Process creation, thread creation, namespaces, cgroups, and copy-on-write combine to implement the familiar process model while sharing many kernel mechanisms.

Why does it matter?

Understanding this model explains why threads share selected resources, why fork can be cheap before memory is modified, and how containers isolate or limit groups of processes without requiring a separate kernel.

Mental model

A process is a collection of kernel-managed resources and one or more tasks. The clone-family system calls choose which resources a new task shares; namespaces change what it can see, while cgroups account for or constrain resource use.

How it works

  • fork creates a child with a logically separate address space; copy-on-write lets parent and child initially share physical pages until one writes.
  • Thread implementations typically create tasks that share an address space and other selected resources, coordinated by the runtime and kernel.
  • exec replaces the calling process's program image while retaining the process identity aspects specified by the API.
  • Namespaces isolate views of resources such as process IDs, mounts, network interfaces, and hostnames.
  • Cgroups organize tasks and apply resource accounting and limits for CPU, memory, and other controllers.

Steps

  • A program calls fork; the kernel creates a child task and sets up copy-on-write mappings.
  • The parent and child execute with separate logical address spaces even if many physical pages are initially shared.
  • The child may call exec to replace its program image with another executable.
  • A container runtime configures namespaces, cgroups, mounts, and security controls before launching the workload.

Real-world usage

  • Debugging process trees, zombies, fork/exec behavior, and resource limits.
  • Understanding containers and why they are not the same as virtual machines.
  • Explaining thread sharing and copy-on-write memory behavior.

Common mistakes

  • Assuming fork immediately copies every physical memory page byte-for-byte.
  • Assuming namespaces alone provide complete container security; capabilities, seccomp, LSMs, mounts, and cgroups also matter.
  • Confusing a process ID with a single CPU-schedulable thread.

Interview questions

Why is fork often inexpensive initially?

Copy-on-write lets parent and child share physical pages until a write requires a private copy.

How do namespaces differ from cgroups?

Namespaces isolate what resources a task can see; cgroups account for and constrain resource consumption.

Prerequisites

Related concepts

Continue learning

Browse the full computer science library