pkill utilities were introduced in Sun’s Solaris 7 and, as g33klord noted, they take a pattern as argument which is matched against the names of running processes. While
pgrep merely prints a list of matching processes,
pkill will send the specified signal (or
SIGTERM by default) to the processes. The common options and semantics between
pkill comes in handy when you want to be careful and first review the list matching processes with
pgrep, then proceed to kill them with
pkill are provided by the the procps package, which also provides other
/proc file system utilities, such as
uptime among others.
killall command is provided by the psmisc package, and differs from
pkill in that, by default, it matches the argument name exactly (up to the first 15 characters) when determining the processes signals will be sent to. The
--exact option can be specified to also require exact matches for names longer than 15 characters. This makes
killall somewhat safer to use compared to
pkill. If the specified argument contains slash (
/) characters, the argument is interpreted as a file name and processes running that particular file will be selected as signal recipients.
killall also supports regular expression matching of process names, via the
There are other differences as well. The
killall command for instance has options for matching processes by age (
pkill can be told to only kill processes on a specific terminal (via the
-t option). Clearly then, the two commands have specific niches.
Note that the
killall command on systems descendant from Unix System V (notably Sun’s Solaris, IBM’s AIX and HP’s HP-UX) kills all processes killable by a particular user, effectively shutting down the system if run by root.
The Linux psmisc utilities have been ported to BSD (and in extension Mac OS X), hence
killall there follows the “kill processes by name” semantics.
pkill is the one that’s worth teaching future generations, both because of the filters you mention and the fact that it’s paired with the highly reusable
pgrep. They kill processes the same way, and neither kills recursively — though with
pgrep, you can select by session (per-tty, think setsid) or process group (think job control).
one difference is that
killalltake exact name of process as the argument whereas
pkill can take partial or complete name.
You can refer this question to know in depth about pkill