Shell, system, and network tools
Linux commands: killall
Learn how the Linux killall command sends a signal to every process with a name, so killall top ends all running top instances, and how to set the signal.
kill targets one process ID. killall targets every process with a given name. That’s convenient, and it’s also why you should be a bit more careful with it.
This is the syntax:
killall <name>
Like kill, it sends a signal, and the default is TERM, the polite request to terminate. We saw the signals in the kill lesson, and they all work here too.
Let’s try it on something harmless. Start two sleep processes in the background:
sleep 60 &
sleep 60 &
Before sending anything, inspect what will match. I never skip this step:
pgrep -a top
pgrep searches running processes by name, and -a prints the full command line on Linux (on macOS use pgrep -l to see the names). For our sleeps:
pgrep -l sleep
# 46564 sleep
# 46565 sleep
Two processes, both ours. Now ask them to terminate normally:
killall -TERM top
TERM gives a program a chance to flush data and clean up. Do the same with killall -TERM sleep, wait a moment, and run pgrep -l sleep again. It prints nothing, and its exit status is 1: no match, both are gone.
Use KILL only when a process won’t respond, because KILL skips the program entirely and the kernel just stops it. No cleanup handlers run:
killall -KILL top
Signals can also mean program-specific actions. HUP often asks a daemon to reload its configuration, but that behavior belongs to the program, not to killall:
killall -HUP top
When nothing matches, killall tells you and exits with status 1. On macOS the message is No matching processes belonging to you were found. On Linux it’s nope: no process found. Either way, nothing happened, which is the safe outcome.
Be careful: process-name matching and the available flags vary between Linux and macOS. Read the local manual with man killall, and never assume a command copied from another operating system has identical behavior.
For one known process, prefer its PID or its service manager, because the target is explicit. killall node ends every Node process you own, including the dev server in another tab you forgot about. Run it with sudo and it reaches other users’ processes too, so the damage gets wider.
Try it on your own: start two sleep 60 processes, inspect them with pgrep, send TERM by name, and confirm both exited.
Lesson completed