Chapter 01 · From program to process01 / 20

A program becomes a process

A program is just a file: machine code and data sitting on disk, doing nothing. This one is called server. Like every Linux executable, it starts with the magic bytes 7f 45 4c 46: 0x7f, then “ELF”.

Run it, and the operating system creates a process: a running instance of the program. The process gets an ID, the PID (here 4127), its own private memory called an address space, a table of open files, and one thread to execute the code: the pink token.

Watch the code and data land in the new process. Then the thread gets a turn on the CPU.

Linux actually maps the file into memory and loads each page the first time it's touched. Same idea, less copying.

terminalin the real world
$ ls -lh /usr/local/bin/server
-rwxr-xr-x 1 root root 2.1M server
$ ./server &
[1] 4127
$ ps -o pid,nlwp,rss,cmd -p 4127
PID NLWP RSS CMD
4127 1 5316 ./server

NLWP is the number of threads ("lightweight processes"). RSS is the memory in use, in KiB.