Processes and Jobs
ps, top, kill, jobs, fg, bg — controlling what runs on your system
Skills taught: linux.ps, linux.kill, linux.top, linux.jobs, linux.background-processes
Viewing processes
# ps: snapshot of current processes
ps # your processes in current terminal
ps aux # ALL processes from ALL users
ps aux | grep nginx # find nginx processes
ps aux | grep -v grep | grep node # find Node.js (exclude grep itself)
# ps output columns:
# USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
# root 1234 0.0 0.1 1024 512 ? Ss 10:00 0:00 nginx
# PID = process ID (unique number for each process)
# top: live process viewer (q to quit)
top
top -u alice # only alice's processes
top -p 1234 # watch specific PID
# htop: better version of top (may need to install)
htop
# pgrep: find PID by name
pgrep nginx # print PIDs of nginx processes
pgrep -la node # PIDs + command names
Killing processes
# kill sends a signal to a process by PID
kill 1234 # SIGTERM (15): graceful shutdown (please stop)
kill -9 1234 # SIGKILL (9): force kill (cannot be ignored)
kill -HUP 1234 # SIGHUP (1): reload config (for servers like nginx)
# pkill: kill by name
pkill nginx # kill nginx gracefully
pkill -9 node # force kill all node processes
# killall: same as pkill
killall -9 node
# Keyboard shortcuts
# Ctrl+C = send SIGINT to foreground process (graceful interrupt)
# Ctrl+Z = suspend foreground process (not kill — pauses it)
Background and foreground jobs
# Run a command in the background with &
python3 server.py & # starts in background, prints PID
npm run dev &
# jobs: list background jobs in current shell
jobs
# [1] Running python3 server.py &
# [2]+ Stopped vim notes.txt
# fg: bring a job to foreground
fg # bring most recent job to foreground
fg %1 # bring job #1 to foreground
# bg: resume a stopped job in background
bg %1 # resume job #1 in background
# Typical workflow:
npm run dev & # start dev server in background
git add . && git commit -m "feat: ..." # do other work
fg # bring dev server back if needed
# nohup: keep running after terminal closes
nohup python3 server.py > server.log 2>&1 &
Frequently Asked Questions
How do I find what is using port 3000?
lsof -i :3000 — lists all processes with an open socket on port 3000. Or ss -tlnp | grep :3000 (faster). Then kill the PID shown. On macOS: lsof -ti :3000 | xargs kill -9 (one-liner to kill the process using port 3000).