Chapter 9: Process and System Monitoring


Linux gives you fine-grained control over running processes, system services, and resource usage. This chapter covers the tools for viewing what is running, controlling processes, managing background jobs, and monitoring system health.


Viewing Processes

ps aux                                 # snapshot of all running processes
ps aux | grep process-name             # filter by name
pgrep process-name                     # print PIDs matching a name
pidof process-name                     # same, for exact binary name

The ps aux output columns: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

The STAT column shows process state: R (running), S (sleeping), Z (zombie), T (stopped).


Interactive Monitoring

For a live, updating view of system resources:

top                                    # built-in, available everywhere
htop                                   # friendlier UI (install: sudo apt install htop)
btop                                   # modern, resource-graph UI (sudo apt install btop)

top/htop shortcuts:


Killing Processes

kill PID                               # send SIGTERM (ask nicely)
kill -9 PID                            # send SIGKILL (force kill, cannot be ignored)
killall process-name                   # kill all processes with this name
pkill process-name                     # same, pattern-matching

Always try kill PID first. kill -9 skips cleanup (open files, locks) and should be a last resort.

# Kill all processes owned by a user
pkill -u username

# Kill a process by name pattern
pkill -f "python script.py"

Background Jobs

The shell’s job control lets you run multiple tasks in one terminal session:

long-command &                         # run in background immediately
Ctrl+Z                                 # suspend a running foreground process
bg                                     # resume suspended process in background
fg                                     # bring background job to foreground
fg %2                                  # bring job #2 to foreground
jobs                                   # list background jobs in current shell

Background jobs are tied to the shell session. If you close the terminal, they stop.

To keep a process running after the shell exits:

nohup long-command &                   # run immune to hangup, output to nohup.out
disown %1                              # detach job #1 from the current shell

# For long-running tasks, tmux or screen are better alternatives
tmux new -s session-name               # start a persistent terminal session

systemd Services

Most modern Linux systems use systemd to manage services (daemons). A service is a background process managed by the init system — it starts on boot, restarts on failure, and logs to the journal.

# Service control (requires sudo)
sudo systemctl start service-name
sudo systemctl stop service-name
sudo systemctl restart service-name
sudo systemctl reload service-name     # reload config without full restart

# Status and enable/disable
systemctl status service-name         # show whether it is running
sudo systemctl enable service-name    # start automatically on boot
sudo systemctl disable service-name   # do not start on boot

# List all services
systemctl list-units --type=service
systemctl list-units --type=service --state=running

Reading service logs with journalctl

journalctl -u service-name             # all logs for a service
journalctl -u service-name -f          # follow live logs
journalctl -u service-name --since "1 hour ago"
journalctl -u service-name -n 50       # last 50 lines

Networking Basics

ip a                                   # list network interfaces and IP addresses
ip route                               # routing table
ss -tulnp                              # listening TCP/UDP ports and which process

The ss output columns: Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process

Quick HTTP requests:

curl https://example.com               # fetch a URL
curl -o file.html https://example.com  # save to file
curl -I https://example.com            # headers only
wget https://example.com/file.zip      # download a file
wget -c https://example.com/file.zip   # resume an interrupted download

Memory and CPU

free -h                                # RAM usage (human-readable)
vmstat 1 5                             # system activity: 5 samples, 1 second apart
uptime                                 # load averages for 1, 5, 15 minutes
nproc                                  # number of CPU cores
lscpu                                  # detailed CPU information

Load average: a value equal to the number of CPU cores means 100% utilization. A value consistently above the core count means the system is overloaded.


Disk I/O

iostat                                 # disk I/O statistics (install: sudo apt install sysstat)
iostat -x 1                            # extended stats, refresh every second
iotop                                  # live per-process I/O (sudo apt install iotop)

Key Takeaways


← Chapter 8: File and Text Utilities Table of Contents Chapter 10: Action Plan →