Pkill - an Easier Linux Kill Command
You learn something new every day. I just learned about the pkill and pgrep commands. I can’t believe I haven’t used these before. Let me give you an example of when they are useful.
My Firefox sometimes does something weird - freezes up, and becomes unresponsive. My usual solution to this is:
$ killall -9 firefox-binI already know that on my system there is no firefox process that can be killed, and that the Firefox binary runs under the name firefox-bin. I know that because I had to track down the right binary to kill the unresponsive app more than once. Pkill solves this tedious lookup problem. I can simply do:
$ pkill firefox
It will automatically look up a PID of the firefox process and kill it. Pgrep on the other hand lets you look up PID’s of processes by name:
$ pgrep -l firefox
25761 firefox-binYou give up some fine grained control (ie, it’s possible that the wrong application will be killed) you no longer have to bother looking up the process name or PID. If you are concerned, you can always use pgrep to find out which PID’s will be killed by pkill and use alternative method if necessary.
Related Posts:

August 1st, 2007 at 11:48 am (5494) [Quote]
Solaris has had this for a while (introduced in Solaris 7). The older versions are located in /usr/proc/bin but others have been sym-linked to /usr/bin.
There are many “p” commands to get info on processes. Solaris had to make-up for not having all the goodies in the /proc tree I guess . . .
Posted usingAugust 1st, 2007 at 1:29 pm (5495) [Quote]
Heh. I definitely love my /proc goodies. ;P
Posted usingOctober 5th, 2007 at 6:54 pm (6444) [Quote]
[…] I mentioned pkill before, so I’m not going to repeat myself. All you need to know is that pkill is a smart fellow. He went to ninja school and is sneaky enough to figure out that when you tell it to kill firefox, you really mean firefox-bin. By that logic Kill and killall are kinda like mob hitmen - effective, but dumb as bricks. You have to tell them exactly who to hit, and how. […]
Posted usingOctober 9th, 2007 at 6:09 pm (6494) [Quote]
This just works for FF because of the same command name prefix and will fail in many other cases while forked processes will not necessarily will follow such naming conventions.
But - nevertheless - these are useful commands.
I knew pkill but missed pgrep - so thanks for the hint.
the polarizer
Posted using