Using htop

Sorting, Filtering and Killing from htop

In htop 386,022 , F6 picks the sort column (P, M, T jump to CPU, memory, time), F4 filters, F5 toggles the tree, u picks a user and H hides threads. Space tags, F9 signals the selection, F7/F8 change priority, and l/s run lsof/strace on it. Flags work too: htop -u www-data, htop -p 178,221, or htop -F ch01-08. Press F9 on burn.php and 15 SIGTERM is preselected: it asks for a clean exit, so try it first. SIGKILL (9) cannot be caught, so buffers are lost and locks stay held; SIGHUP makes many daemons reload. In the shell, kill takes a PID and pkill -f a pattern (use a full path).

Lowering a CPU hog's priority, then stopping itShell
nice -n 10 php /tmp/ch01-08/burn.php > /dev/null &
sleep 2; ps -o pid,ni,%cpu,cmd -p $!
renice -n 15 -p $!      # an ordinary user may lower priority...
renice -n 5 -p $!       # ...but not raise it again
kill -TERM $!; sleep 0.5; kill -0 $! || echo gone
Output
    PID  NI %CPU CMD
  14353  10  100 php /tmp/ch01-08/burn.php
14353 (process ID) old priority 10, new priority 15
renice: failed to set priority for 14353 (process ID): Permission denied
bash: kill: (14353) - No such process
gone
[1]+  Terminated                 nice -n 10 php /tmp/ch01-08/burn.php > /dev/null

Niceness runs from -20 to 19 and only root may lower it. A niced job still takes an idle core: it yields only to competition. kill -0 sends nothing; it tests whether the PID exists.