RH124 Ch 8: Monitoring and Controlling Processes

A process is a running program with a PID, an owner, a state (R running, S sleeping, D waiting on I/O, T stopped, Z zombie) and a priority.

Seeing them - ps aux — everything; ps -ef --forest shows parents; ps -eo pid,ni,%cpu,%mem,cmd --sort=-%cpu | head finds hogs. - top: P sort by CPU, M by memory, k kill, r renice, q quit. Load average shows demand over 1, 5 and 15 minutes — compare it to the CPU count (nproc). - pgrep -l name, pgrep -u user, pidof program.

Signals - kill PID sends 15 (TERM, ask nicely). kill -9 PID (KILL) cannot be caught — use it only when TERM fails. kill -1 (HUP) often makes daemons reload. - pkill name, pkill -u intern, killall name act on many processes at once.

Jobs: cmd & runs in the background, jobs lists, fg %1/bg %1 move them, Ctrl+Z suspends, Ctrl+C interrupts.

Priority (nice): values run from -20 (most favoured) to 19 (least). Normal users can only make things nicer (higher). - Start: nice -n 15 backup.sh. - Change: renice -n 10 -p PID (or -u user for all of a user's processes).

Exam tips: write down the PID before killing if the task asks for it; check with ps -o pid,ni,cmd -p PID that the nice value really changed; kill the process, not its parent shell, unless asked.