What You'll Learn
Every program running on Linux is a "process." This guide teaches you how to see what's running, kill misbehaving programs, and manage background services.
Seeing What's Running
ps — Snapshot of Processes
ps aux # Show ALL processes (most common usage)
ps -ef # Full-format listing
ps --forest # Show process tree hierarchy
The ps aux output columns:
| Column | Meaning |
|---|---|
| USER | Who owns the process |
| PID | Process ID (unique number) |
| %CPU | CPU usage percentage |
| %MEM | Memory usage percentage |
| COMMAND | The program being run |
top — Live Process Monitor
top # Interactive process viewer (press q to quit)
htop # Colorful, user-friendly version (may need: sudo apt install htop)
In top/htop you can:
- Press F or arrow keys to sort by CPU, memory, etc.
- Press the PID number (in htop) to kill a process.
- Press q to quit.
Killing Processes
kill PID # Gracefully stop a process (SIGTERM)
kill -9 PID # Force-kill a process (SIGKILL — use as last resort)
pkill nginx # Kill all processes named "nginx"
killall firefox # Kill ALL Firefox processes
How It Works
kill PIDsends SIGTERM (signal 15) — the process can clean up and exit nicely.kill -9 PIDsends SIGKILL — the kernel kills it immediately. No cleanup.- Always try graceful kill first before using
-9.
Background Jobs
sleep 300 & # Run a command in the background
jobs # List your background jobs
fg %1 # Bring job 1 to the foreground
Ctrl+Z # Pause (suspend) the current foreground job
bg %1 # Resume paused job 1 in the background
Nohup — Run Even After You Log Out
nohup python3 server.py & # Keep running after you disconnect
# Output goes to nohup.out by default
Managing Services with systemctl
Services are programs that run in the background (web servers, databases, SSH).
sudo systemctl start nginx # Start a service
sudo systemctl stop nginx # Stop a service
sudo systemctl restart nginx # Restart a service
sudo systemctl status nginx # Check if it's running + recent logs
sudo systemctl enable nginx # Start automatically at boot
sudo systemctl disable nginx # Don't start at boot
systemctl list-units --type=service --state=running # List all running services
Practice Exercise
ps aux | head -20 # See the first 20 processes
top # Watch live process activity (q to quit)
sleep 1000 & # Start a background job
jobs # See it listed
kill %1 # Kill your background job
Troubleshooting
- "Operation not permitted" on kill: You can only kill processes you own. Use
sudo kill PID. - Service won't start: Check logs with
systemctl status service-nameorjournalctl -u service-name.
What's Next?
You can manage processes — now learn about networking:
Networking Basics →