The killall Command

The killall command is used to kill (i.e., terminate) all processes (i.e., running instances of programs) associated with programs whose names are provided to it as arguments (i.e., inputs).

Thus, it can be viewed as a handy alternative to the kill command, which is used to terminate specific processes whose process ID numbers (PIDs) are provided to it as arguments.

kill and killall are utilized mainly to efficiently and cleanly terminate programs that have frozen and thus cannot be closed by conventional means (i.e., by selecting a menu item, by pushing a button in a GUI, or by issuing a command). They eliminate the need to reboot (i.e., restart the computer) in order to close the program.

The PIDs can be obtained by first using the ps command, which lists the names and PIDs of processes currently on the system. Alternatively, they can be obtained by using the pstree command, which shows current processes in a tree diagram.

Although the combination of ps and kill (or pstree and kill) is commonly employed and is often quite effective, there are situations in which it is either inconvenient or will not work. For example, sometimes it is difficult to determine what are the processes associated with a non-responding program, despite all of the information that can be gleaned from ps and pstree. killall bypasses this problem by just requiring the name of the program rather than one or a series of PIDs.

killall can also be useful in the case of a rare malfunction in which the system keeps spawning multiple instances of a program. It can be difficult, if not impossible, to track down the PIDs for all of these instances using PS and then attempt to terminate each individually using kill.

killall's basic syntax is

killall [options] program_name(s)

When used with no options, killall sends a signal to terminate all instances of all program names that are provided as arguments. For example, if it is desired to abruptly terminate nautilus (which is the official file manager for the GNOME desktop), the following command would be issued:

killall nautilus

Unlike the kill command, it is not necessary to first try to find the PID(s) for nautilus. And if there are multiple instances of nautilus running, all will be terminated immediately.

The -i option interactively asks the user for confirmation before killing each process. This makes it possible to kill only selective instances of a program, as is done routinely with kill.

If a user is running multiple instances of killall on the system, a killall process can terminate all of them except for itself. That is, a killall process never kills itself.

An ordinary user is only able to terminate its own processes, and thus it is not necessary to be concerned about the processes of other users on a multi-user system. However, when used by the root (i.e., administrative) user, killall can affect processes started by all users.

If a command name is longer than 15 characters, its full name might not be available, in which case killall by default will terminate every process whose name matches the first 15 characters. The -e option tells killall to require an exact match for long names, and thus such entries are skipped. killall returns a message for each skipped entry if the -v (i.e., verbose) option is specified along with the -e option.

The -g option tells killall to terminate the entire process group to which the specified process belongs. The kill signal is only sent once per group, even if multiple processes belonging to the same process group were found.

The -l option tells killall to list all known signal names. The -s option specifies the type of signal to send. If -s is not used and no signal is specified, the killall command sends a SIGTERM signal, which is the same as the default signal for the kill command. killall is usually effective without specifying any signal.

The -q (i.e., quiet) option, which can be considered the opposite of the -v option, tells killall to provide no feedback about the processes that are killed. The -V option (not to be confused with the -v option) provides information about the installed version of killall.

The -w option tells killall to wait for all designated processes to die. killall checks once per second to see if any of the supposedly killed processes still exist; thus, it may wait forever if the signal was ignored, if it had no effect, or if the process remains in a zombie (i.e., defunct) state. This option does not detect the rare situation in which a process disappears and is replaced by a new process with the same PID.

Killing by file name only works for executables (i.e., runnable programs) that are kept open during execution. Also, killall may not have the desired effect in some situations, including on some non-Linux systems, in which case kill provides a viable alternative.

Created August 24, 2005. Updated June 5, 2007.
Copyright © 2005 - 2007 The Linux Information Project. All Rights Reserved.