Practical Professional Linux — Foundation

Chapter 7 · Skill Level: Foundation

Process Management

Observe, signal, prioritise, and manage processes and background jobs.

Processes are the unit of execution in Linux. Confident process management — listing, signalling, prioritising, and backgrounding — is essential for keeping systems responsive and is a core exam topic.

By the end of this chapter you will be able to

  • Inspect processes with ps and top/htop.
  • Interpret PID, state, CPU, and memory columns.
  • Send signals (SIGTERM, SIGKILL, SIGHUP) appropriately.
  • Manage foreground/background jobs and detach long tasks.
  • Adjust scheduling priority with nice and renice.

7.1 Observing Processes

Listing processes
ps aux                 # one-time snapshot of every process
ps aux --sort=-%cpu | head  # top CPU users
top                    # live, updating view (q to quit)
# htop is a friendlier top — install it if you can

Each process has a unique PID. You’ll use that number to signal or prioritise it.

7.2 Signals and Termination

Signal Meaning
SIGTERM (15) Polite ‘please stop’ — the default. Lets the program clean up. Try this first.
SIGKILL (9) Forceful ‘stop now’ — cannot be caught. Last resort; may lose data.
SIGHUP (1) ‘Reload’ for many services, or hang-up.
Signalling processes
kill 4821        # SIGTERM (polite)
kill -9 4821     # SIGKILL (force) — only if it ignores TERM
pkill firefox    # by name
killall nginx    # all matching processes

7.3 Jobs and Backgrounding

Command Effect
command & Start it in the background.
Ctrl+Z Pause the foreground job.
jobs List backgrounded jobs.
fg %1 / bg %1 Resume job 1 in fore/background.
nohup cmd & Keep running after you log out.

7.4 Scheduling Priority

nice sets how much CPU priority a process asks for (-20 = greedy, 19 = generous). renice changes it for a running process.

7.5 Guided Lab: Process Triage

Estimated time: 20 minutes. Create a busy process, find it, prioritise it, then stop it cleanly.

  • Start a harmless background load: sleep 600 & (note the PID it prints).
  • List it: ps aux | grep sleep and jobs.
  • Watch the live view with top for a few seconds, then quit with q.
  • Lower its priority: renice -n 10 -p <PID>.
  • Stop it politely: kill <PID>; confirm it’s gone with ps aux | grep sleep.
  • Start another sleep 600 &, then practise force-stop: kill -9 <PID> (note: only because this is a safe throwaway).

Troubleshooting

Symptom Likely cause and fix
A process won’t die with kill It’s ignoring SIGTERM or stuck in uninterruptible I/O. Try kill -9; if even that fails, the process is waiting on hardware/NFS — investigate the I/O source.
High CPU but you can’t tell which process Use top/htop sorted by CPU, or ps aux –sort=-%cpu | head. Note the PID and command.
Background job died when I logged out Plain & doesn’t survive logout. Use nohup cmd & or run it inside tmux/screen.
System slow, memory full Check free -h and top sorted by memory; a leak or runaway may need restarting. Persistent issues point to Chapter 13 tuning.

Practice & Prove It

Write-the-command drills

  • Show all processes sorted by CPU usage, highest first.
  • Find the PID(s) of every process named sshd.
  • Politely terminate the process with PID 5005.
  • Force-kill PID 5005 after it ignored the polite signal.
  • Start the script ./long.sh so it keeps running after you log out.

Quick quiz

  • What identifies a single process?
  • Which signal is the default, polite stop?
  • When should you use kill -9?
  • What does appending & to a command do?
  • Which command changes a running process’s priority?

Key Takeaways

  • Every running program is a process with a unique PID.
  • ps gives a snapshot; top/htop give a live view sorted by CPU or memory.
  • Stop processes with SIGTERM first; reserve SIGKILL (-9) for last resort.
  • Manage background jobs with &, jobs, fg/bg; use nohup or tmux to survive logout.
  • nice/renice adjust CPU priority for batch or greedy processes.

Next — Chapter 8: storage fundamentals — devices, filesystems, mounting, and LVM.