Process Management and Services

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:

ColumnMeaning
USERWho owns the process
PIDProcess ID (unique number)
%CPUCPU usage percentage
%MEMMemory usage percentage
COMMANDThe 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:

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

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

What's Next?

You can manage processes — now learn about networking:

Networking Basics →