AtomLearnAtomLearn
DashboardGoalsPathAchievementsReviewSign In
Linux & Command LineNot Started

Processes & Jobs

List, monitor, and control running processes — the key to debugging and resource management

0%
Knowledge0%
Learn & Drill
Fluency0%
Drill & Speed
Retention0%
Mastery & Review
Confidence0%
All modes
Practice
Knowledge
Fluency
Retention

Knowledge Debt detected

You can study this freely — but your score may plateau if these foundations have gaps. The Mastery badge requires them to be solid.

Explanation

Every running program on Linux is a process with a unique PID (Process ID). Knowing how to find, inspect, and stop processes is essential for debugging servers and managing resources.

Listing processes:

bash ps aux # all processes, all users, in detail ps aux | grep nginx # filter for a specific process # ps columns: USER PID %CPU %MEM VSZ RSS STAT START TIME COMMAND # USER=owner, PID=process ID, %CPU/%MEM=resource usage, STAT=status

Live monitoring:

bash top # live updating process list (q to quit) htop # better version of top — color, mouse support (install separately) `` In top/htop: sorted by CPU by default. Press M to sort by memory, k to kill by PID.

Killing processes:

bash kill PID # send SIGTERM (15) — polite shutdown, process can clean up kill -9 PID # send SIGKILL — force kill, no cleanup (last resort) kill -HUP PID # SIGHUP — reload config (nginx, gunicorn) killall nginx # kill all processes named nginx pkill -f "gunicorn"# kill by matching command pattern

Background and foreground jobs:

bash ./long_script.sh & # run in background (& at the end) jobs # list background jobs for this shell session fg 1 # bring job #1 to foreground bg 1 # resume stopped job in background # Ctrl+C — send SIGINT (terminate) # Ctrl+Z — pause and send to background (SIGTSTP)

Keeping processes alive after logout:

bash nohup ./server.py & # run ignoring hangup signal nohup ./server.py > out.log & # with log capture # Better: use tmux or screen (session survives SSH disconnect) tmux new -s mysession # create named session tmux attach -t mysession # reattach later

Process tree and parent/child:

bash pstree # show processes as a tree pstree -p # show PIDs too pgrep nginx # list PIDs of processes matching name

Examples

Finding and killing a stuck process

Always try SIGTERM first — it lets the process clean up connections and write buffers. Use -9 only when the process is truly stuck.

# A gunicorn worker is hanging and eating 100% CPU
# Step 1: find it
ps aux | grep gunicorn
# bill    1847  99.9  2.1  /usr/bin/python -m gunicorn app:app
# bill    1848   0.0  1.8  /usr/bin/python -m gunicorn app:app --worker

# Step 2: try graceful shutdown first
kill 1847         # sends SIGTERM — worker has a chance to finish requests

# Step 3: if it does not die, force it
kill -9 1847      # SIGKILL — instant death, no cleanup

# Alternative: kill by name
killall -9 gunicorn

# Or reload config without killing (zero-downtime restart)
kill -HUP 1847   # gunicorn re-reads config and replaces workers

Running a server in the background and monitoring it

Use `jobs` to see what is running in the background in your shell. Use `ps aux` to see everything system-wide.

# Start a Python server in the background
python -m http.server 8080 &
# [1] 2043   — job #1, PID 2043

# List background jobs
jobs
# [1]+ Running    python -m http.server 8080 &

# Monitor resource usage live
top
# PID   USER  %CPU %MEM  COMMAND
# 2043  bill   0.3  0.1  python -m http.server

# Find memory hogs
ps aux --sort=-%mem | head -10

# Bring the server back to foreground
fg 1
# Then Ctrl+C to stop it

# Or kill it directly
kill 2043

How well did you understand this?

Next in Linux & Command Line

SSH

Continue