What is the difference between kill , pkill and killall?
The kill
command is a very simple wrapper to the kill
system call, which knows only about process IDs (PIDs). pkill
and killall
are also wrappers to the kill
system call, (actually, to the libc library which directly invokes the system call), but can determine the PIDs for you, based on things like, process name, owner of the process, session id, etc.
How pkill
and killall
work can be seen using ltrace
or strace
on them. On Linux, they both read through the /proc
filesystem, and for each pid (directory) found, traverses the path in a way to identify a process by its name or other attributes. How this is done is technically speaking, kernel and system specific. In general, they read from /proc/<PID>/stat
which contains the command name as the 2nd field. For pkill -f
and pgrep
examine the /cmdline
entry for each PID's proc entry.
pkill
and pgrep
use the readproc
system call, whereas killall
does not. I couldn't say if there's a performance difference: you'll have to benchmark that on your own.
kill and killall are tools which provide a way to kill a process. The first by its PID, the second by its name. pgrep (list) and pkill (kill by default) are tools which provide a way to send message to a process by its name or other attributes see: http://linux.die.net/man/1/pkill For more info about signals: http://linux.die.net/man/7/signal