Part II · Your system
16. Processes & scheduling
hub
What's running, who started it, what it costs, and how to stop it.
On your machine
$ atfq processes Total 8 processes: 1 running, 3 sleeping, 1 waiting on I/O (D), 1 idle kernel thread, 2 zombies Zombies PID 4242 worker (old), parent 4100 supervisor PID 4300 orphan-job, parent 9999 Waiting PID 5000 rsync, parent 1 systemd Memory supervisor (793.0 MiB, PID 4100), rsync (239.3 MiB, PID 5000), systemd (11.7 MiB, PID 1) CPU time rsync (1 min 35 s, PID 5000), supervisor (25 s, PID 4100), systemd (5 s, PID 1), kthreadd (0 s, PID 2), kworker/0:0-events (0 s, PID 3)
An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.
Commands
ps aux --sort=-%mem | head- processes using the most memory
top- live view; press M for memory, P for CPU
pgrep -a nginx- find processes by name, with their command 16.2
pstree -p- who started whom, with PIDs
kill 1234- ask a process to stop 16.2
systemd-cgls- processes grouped by service and session 16.4
Paths
/proc/PID/- everything about one process
/proc/PID/status- state, memory, threads, owner
Cards
- 16.1Process states and zombiesEvery process has a one-letter state: R running, S sleeping, D waiting on I/O, T stopped, Z zombie.
- 16.2SignalsA signal is a short message the kernel hands to a process: stop, pause, continue, reload.
- 16.3nice and prioritiesNiceness goes from -20 (greedy) to 19 (polite). The default is 0.
- 16.4cgroupsA cgroup is a group of processes that the kernel measures and limits together: CPU, memory, disk I/O, number of processes.
Also about this
- 1.5How a program starts: fork and execA new process starts as a copy of an existing one: fork() duplicates the process that calls it.
- 1.2How the kernel shares the CPUsThere are more tasks wanting a CPU than CPUs, so the scheduler gives each a short turn, then switches: a context switch.
- 18.1Load averageLoad average: the number of tasks running or waiting for a CPU, plus those waiting on disk (D state), averaged over 1, 5 and 15 minutes.
- 17.2The OOM killerWhen RAM and swap are both used up, the kernel's OOM ("out of memory") killer picks a process and kills it to get memory back.