Chapter 8: Processes

Linux processes cheat sheet

The chapter on one page: what to remember, the commands to have at your fingertips, and flashcards for quick revision.

The chapter in eight sentences

Cheat sheet

Look

CommandDoes
ps aux, ps -ef --forestAll processes; with the tree
ps -o pid,ppid,stat,ni,cmd -p PIDChosen columns for one process
ps aux --sort=-%mem | headBiggest memory users
pstree -ps $Ancestors of your shell
pgrep -a NAME, pgrep -u USERFind by name or owner
top, uptime, free -h, nprocLive view, load, memory, CPUs

Jobs and signals

CommandDoes
cmd &, jobs, fg %N, bg %NBackground, list, move
Ctrl+Z, Ctrl+CPause, interrupt
nohup cmd &Survive a hangup
kill PID, kill -9 PIDTerminate, force
kill -STOP PID, kill -CONT PIDPause, resume
pkill NAME, pkill -u USER, killall NAMEMany at once
kill -lList signals (1 HUP · 2 INT · 9 KILL · 15 TERM · 18 CONT · 19 STOP)

Priority and tuning

CommandDoes
nice -n 10 cmdStart with lower priority (-20 to 19)
renice -n 5 -p PIDChange a running process
tuned-adm list, active, recommendInspect profiles
tuned-adm profile NAMESwitch profile

Flashcards

What are PID and PPID?
The process ID, and the ID of the process that started it (its parent).
How does a shell run an external command?
It forks a child copy, which execs the program; the shell waits and collects the exit status.
What do the ps STAT letters R, S, D, T, Z mean?
Running, sleeping, uninterruptible disk wait, stopped, zombie.
Two commands that list all processes?
ps aux and ps -ef (add --forest for the tree), or pstree.
Run a command in the background, list jobs, bring one back?
cmd & · jobs · fg %N
Pause the foreground job and continue it in the background?
Ctrl+Z, then bg
Which signal does kill send by default, and what is the last resort?
15 (TERM). The last resort is kill -9 (KILL).
End all processes named foo, or owned by bob?
pkill foo · pkill -u bob
Preview what pkill would match?
pgrep -a PATTERN
How do you judge a load average?
Divide by the number of CPUs (nproc). About 1 per CPU is full.
Start a command with low priority, and change a running one?
nice -n 10 cmd · renice -n 15 -p PID
Show and set the performance profile?
tuned-adm active · tuned-adm profile NAME · tuned-adm recommend