Thursday, December 3, 2026 | London 10°C · Drizzle
DailyGlimpse

AI

Linux Process Creation Demystified: The fork() + exec() Dance

Techsecure 1 min read

Ever wondered what really happens when you type python app.py in your Linux terminal? The OS doesn't just magically create a process—it follows a precise two-step system call sequence: fork() and exec().

  1. fork() duplicates the current process, creating a child process that is nearly identical to its parent.
  2. exec() replaces the child's memory space with a new program (e.g., Python interpreter) and starts execution from its entry point.

The kernel loads the program's code and data into memory, sets up the stack and heap, and hands control to the CPU. The CPU then begins executing instructions from the new program.

This two-step approach is unique to Unix-like systems. Windows uses a single CreateProcess() API that combines both steps. Linux's design was chosen for flexibility—the parent can modify the child's environment between fork() and exec(). Additionally, Copy-on-Write (CoW) makes fork() extremely efficient by sharing memory pages initially and copying only when modified.

Understanding this fundamental mechanism demystifies how operating systems juggle multiple programs. Stay tuned for a deep dive into why Unix chose fork()+exec() and how Copy-on-Write optimizes performance.

React