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-bin
I 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-bin
You 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.
[tags]pkill, pgrep, kill, killall, linux kill, killing processes, linux[/tags]