How to kill and send signals to processes
Topic: Servers linux
Summary
Send SIGTERM or SIGKILL to a process with kill or killall; use signals to stop, reload, or force-stop. Understand what each signal does so you can stop runaway or stuck processes safely.
Intent: How-to
Quick answer
- kill PID sends SIGTERM (graceful); kill -9 PID sends SIGKILL (force); killall -9 name kills all processes with that name; use SIGTERM first.
- Other signals: kill -HUP PID (reload), kill -USR1 (app-specific); check with kill -l; process must be owned by you or you need root to signal.
- Zombies (state Z) are reaped by the parent; kill the parent process to clear them; orphaned zombies are reaped by init.
Prerequisites
Steps
-
Find the PID
pgrep name or ps aux | grep name; note the PID; use ps -ef for parent (PPID) if you need to kill a group.
-
Send SIGTERM first
kill PID or kill -15 PID; wait a few seconds; if still running, kill -9 PID; for service prefer systemctl stop so the unit is stopped cleanly.
-
Kill by name or group
killall name (SIGTERM) or killall -9 name; to kill process tree: pkill -P PPID or kill the parent so children get SIGHUP or follow.
-
Handle zombies
Zombies cannot be killed; find parent with ps -o ppid= -p ZOMBIE_PID; restart or kill the parent so kernel reaps the zombie.
Summary
You will send signals to processes with kill and killall, prefer SIGTERM then SIGKILL, and clear zombies by killing the parent. Use this to stop runaway or stuck processes.
Prerequisites
- Shell access; same user as the process or root to signal others.
Steps
Step 1: Find the PID
pgrep -a nginx
ps aux | grep nginx
Step 2: Send SIGTERM first
kill 12345
sleep 3
kill -9 12345
Step 3: Kill by name or group
killall nginx
killall -9 nginx
Step 4: Handle zombies
ps -o ppid= -p ZOMBIE_PID
kill PARENT_PID
Verification
- Process is gone (ps or pgrep); service can be restarted cleanly.
Troubleshooting
Process respawns — Managed by systemd/supervisor; use systemctl stop or disable the unit.
Cannot kill — Process in D state (uninterruptible); fix underlying I/O or reboot.