Linux Basics
Monitor, control, and manage running processes on Linux using ps, top, kill, and systemd.
Contents
View Running Processes
# Snapshot of all processes
ps aux
# Show as tree
ps auxf
# Find a specific process
ps aux | grep nginx
# Interactive process monitor
top
htop # install with: sudo apt install htop
Send Signals to Processes
# Kill by PID (graceful SIGTERM)
kill 1234
# Force kill (SIGKILL - no cleanup)
kill -9 1234
# Kill by name (all matching)
pkill nginx
# Kill all instances of a program
killall -9 python3
# Reload a process (SIGHUP)
kill -HUP 1234
Background Jobs
# Run in background
./long-script.sh &
# List background jobs
jobs
# Bring job to foreground
fg %1
# Send running process to background
Ctrl+Z # pause the process
bg %1 # resume it in background
# Run immune to terminal close
nohup ./script.sh > output.log 2>&1 &
Manage Services with systemd
# Start / stop / restart
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
# Enable at boot
sudo systemctl enable nginx
sudo systemctl disable nginx
# Check status
sudo systemctl status nginx
# View service logs
sudo journalctl -u nginx -f --since "1 hour ago"
Process Priority (nice)
# Start process with low priority (nice -20 = highest, 19 = lowest)
nice -n 10 ./backup.sh
# Change priority of running process
sudo renice -n 5 -p 1234
# View current priorities in top: press 'r' to renice
top
Check Resource Usage
# Memory and CPU by process
ps aux --sort=-%mem | head -10
ps aux --sort=-%cpu | head -10
# Open file handles per process
ls -l /proc/1234/fd | wc -l
lsof -p 1234
# Check which process owns a port
sudo ss -tulpn | grep :80