ps / top / htop
Every running program is a process with a PID, parent, state, and resource usage. ps snapshots them; top / htop show them live; kill / pkill signal them; nohup / & / disown background them.
Inspect, signal, background
EXAMPLE
# Inspect — modern alternatives in parens ps aux # everyone's processes ps -ef # similar, BSD vs SysV style ps -p $$ # current shell ps --forest # tree view top # live, refresh htop # nicer top (install: brew/apt install htop) btop # newer, prettier # Filtering ps aux | grep -v grep | grep nginx pgrep -af nginx # PIDs matching a name pgrep -u ada # PIDs of a user # Resource usage on a PID ps -p $PID -o pid,user,%cpu,%mem,etime,cmd # Signals kill <PID> # default = SIGTERM (15) kill -9 <PID> # SIGKILL — last resort, no cleanup kill -HUP <PID> # SIGHUP — reload config in many daemons kill -INT <PID> # SIGINT — like Ctrl+C pkill -f myscript.sh # kill by command-line match killall nginx # Foreground / background longrun.sh & # run in background jobs # list current shell's jobs fg %1 # bring job 1 back bg %1 # send to background Ctrl + Z, then bg # pause + send to background # Survive a logout nohup longrun.sh > out.log 2>&1 & disown # detach from the shell # Modern alternative: tmux / screen / systemd-run --user --scope # Open files / sockets a process holds lsof -p $PID lsof -i :8080 # who's on this port? ss -ltnp | grep :8080 # modern replacement # Memory + CPU details (Linux) cat /proc/$PID/status cat /proc/$PID/limits
Why it matters
kill -9 kills without cleanup — flushes nothing, runs no shutdown hooks. Default to kill (TERM) and only escalate to -9 when the process won’t respond.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Discussion
Loading…