[Techtalk] pkill and pgrep - your friends

Val Henson val.henson at gmail.com
Tue May 2 10:40:17 EST 2006


After Carla's recent article on killing, :) no doubt a few of you
played around with kill.  One annoying thing about sending signals
using kill is that you have to first look up the process id, then copy
that into the kill command line.  What a pain!  Well, a more powerful
(and more dangerous) method is the pkill command.  pkill sends the
signal to any process with the specified string as part of the process
name.  For example:

$ pkill ssh

Will send the TERM signal to any ssh process running - and also any
sshd process, which might not be what you intended.  See the pkill man
page for information which will help you make this a little safer,
such as the -f option to match against the entire command line.

pgrep will return the pid of any process with the given string in its
name.  This is really useful to find out which process are running,
instead of running ps | grep <whatever>.

$ pgrep ssh
9095
9295
29041

-VAL


More information about the Techtalk mailing list