What's the difference between pkill and killall?

37,328

Solution 1

The pgrep and 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 pgrep and 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. pgrep and pkill are provided by the the procps package, which also provides other /proc file system utilities, such as ps, top, free, uptime among others.

The 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 -e, --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 -r, --regexp option.

There are other differences as well. The killall command for instance has options for matching processes by age (-o, --older-than and -y, --younger-than), while 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.

Solution 2

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).

Solution 3

One difference is that killall takes the exact name of process as the argument whereas pkill can take partial or complete name.

You can refer to the following question to know in depth about pkill

Solution 4

killall - kill processes by name. Use the killall command to send a signal to one or more processes matching selection criteria, such as command name, processes owned by a specific user, or all system-wide processes.

pkill - will send the specified signal (by default SIGTERM) to each process instead of listing them on stdout. pkill can signal multiple processes like killall, but can also use advanced selection criteria that can include any combination of:

Command UID Parent Terminal

Share:
37,328

Related videos on Youtube

mavillan
Author by

mavillan

Currently pursuing Master's degree in Computer Science at UTFSM. I'm highly interested in Numerical Methods and Scientific Computing.

Updated on September 18, 2022

Comments

  • mavillan
    mavillan over 1 year

    I know that pkill has more filtering rules than killall. My question is, what is the difference between:

    pkill [signal] name
    

    and

    killall [signal] name
    

    I've read that killall is more effective and kill all processes and subprocesses (and recursively) that match with name program. pkill doesn't do this too?