A process is the OS’s abstraction of a running program: a program in execution. The simplest case is one address space with a single thread of execution.

What’s in a process

A process consists of at least:

  • an address space, containing the code (instructions) and data of the running program
  • at least one CPU state, consisting of the instruction pointer (EIP), stack pointer (ESP), and the other general purpose registers
  • a set of OS resources, including open files, open pipes, open network connections, and so on

Address space

The stack grows down: push decrements ESP, pop increments it. The stack contains all runtime frames.

A process’s address space, idealized:

+----------------------+ <- 0x7FFFFFFF
|        Stack         |
|   (dynamic memory)   |
+----------------------+ <- ESP
|          |           |
|          v           |
|                      |
|          ^           |
|          |           |
+----------------------+
|        Heap          |
|   (dynamic memory)   |
+----------------------+
|        Data          |
|   (data segment)     |
+----------------------+
|        Code          | <- EIP
|   (text segment)     |
+----------------------+ 0x00000000

OS process namespace

  • Each process has a unique identifier, the PID.
  • The PID namespace is global to the OS.
  • Operations that create processes (e.g. fork) return the PID.
  • Operations on processes (e.g. kill) take a PID as an argument.