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 logTo stop a process you send it a signal with kill:
kill 4312sends SIGTERM (15), the default: "please shut down". The program can finish requests, flush files and exit cleanly.kill -9 4312sends 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.
The shortcut
Find, inspect, signal gently, force last. Never jump straight to kill -9.
Find
sudo ss -ltnpshows port 8000 held bypython, PID 4312.
The trap: killing the wrong PID because you matched a pattern too loosely. Always inspect the full command line before you signal.
Drills
Answer fast — trust the rule.
Which signal does kill 4312 send when you give no option?
Why try SIGTERM before SIGKILL?
Which command shows the process listening on port 8000?
You kill a process that belongs to a systemd service, and a new PID appears seconds later. Why?
Remember
- Every running program is a process with a PID: find it, inspect it, signal it.
- Shortcut: find, inspect, signal gently, force last.
- Trap:
kill -9on a PID you have not inspected.
