The Plain Picture#
The hotel manager's register of guests from Operating Systems — now you get to read it, and ask guests to leave.
The Real Names and Commands#
ps aux # every process: user, PID, %CPU, %MEM, command
ps aux | grep uvicorn # find the StudyBuddy server process
pgrep -fl uvicorn # the same, more neatly: PIDs + command lines
top # live view sorted by CPU; q to quit (htop is a friendlier version)
kill 4242 # send SIGTERM to PID 4242 — "please stop" (02_operating_systems.md Ch 12)
kill -9 4242 # SIGKILL — "die now", no clean-up. Last resort only
pkill -f uvicorn # signal every process whose command line matchesJobs — running things in the background of your shell:
python3 long_task.py & # & = start it in the background; you get the prompt back
jobs # list this shell's background jobs
fg %1 # bring job 1 back to the foreground
# Ctrl+Z pauses the foreground job; then `bg` resumes it in the background
nohup python3 long_task.py > task.log 2>&1 & # keep running even after you log outReading top's header:
load average: 3.52, 2.10, 1.05The load average is roughly the number of processes running or waiting to run, averaged over the last 1, 5 and 15
minutes. Compare it with the number of cores (nproc on Linux, sysctl -n hw.ncpu on Mac): load 3.5 on 8 cores is
fine; load 30 on 8 cores means everything is queueing. Rising numbers (1.05 → 2.10 → 3.52) mean the load is growing.
Gotchas
kill -9first is a bad habit. The process can't flush buffers, finish requests or remove lock files. Always try plainkill(SIGTERM) and wait a few seconds.Background jobs with
&die when you close the SSH session unless you usenohup— or, much better on servers, run things as proper services (Ch 11), or insidetmux(a terminal that keeps running on the server after you disconnect).
Check yourself
4 questionsHow do you find the PID of a running uvicorn server?
Show answerHide answer
pgrep -fl uvicorn (or ps aux | grep uvicorn).
kill vs kill -9?
Show answerHide answer
kill sends SIGTERM (graceful, can be handled); kill -9 sends SIGKILL (immediate, can't be caught).
A server with 4 cores has load average 12.0, 11.5, 11.8. What does it mean?
Show answerHide answer
About 3× more runnable work than cores, steadily for 15 minutes — it's overloaded.
How do you keep a long command running after you log out?
Show answerHide answer
nohup cmd > log 2>&1 &, or tmux, or better, run it as a systemd service.