Skip to the workspace
Pebellslearn by building
Terminal Knowledge  ›  Lesson

Process Monitoring — Find It, Inspect It, Signal It

Process Monitoring 12 minEvery running program has a PID that you can find with ps, pgrep, ss or lsof, inspect, and stop with a polite SIGTERM before resorting to SIGKILL.

devops / Process Monitoring — Find It, Inspect It, Signal It

Explore each scene at your own pace.

01 · The rule

The rule

Process Monitoring — Find It, Inspect It, Signal It

You restart notes-api and it refuses to start: "address already in use". Something is still holding port 8000. To fix it you need to find that process, understand what it is, and stop it without making things worse.

The rule

Every running program is a process with a PID: find it, inspect it, signal it.

The kernel gives every running program a process ID (PID). The tools you need:

ps aux                      # every process, with user, CPU, memory, command
pgrep -af notes-api         # PIDs and full command lines matching a pattern
top                         # live view, busiest first (htop is a friendlier version)
sudo lsof -i :8000          # which process has port 8000 open
sudo ss -ltnp               # every listening TCP port and its process
systemctl status notes-api  # a systemd service's state, PID and last log lines
journalctl -u notes-api -n 50   # the service's recent log

To stop a process you send it a signal with kill:

  • kill 4312 sends SIGTERM (15), the default: "please shut down". The program can finish requests, flush files and exit cleanly.
  • kill -9 4312 sends SIGKILL: the kernel ends it immediately. No clean-up, open work is lost.
  • kill -HUP (SIGHUP) asks many daemons, such as nginx, to reload their configuration.

If the process belongs to a systemd service, stop it with systemctl stop instead, or systemd may simply start it again.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.