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-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]

This entry was posted in Uncategorized. Bookmark the permalink.



4 Responses to Pkill – an Easier Linux Kill Command

  1. Craig Betts UNITED STATES Mozilla Firefox Solaris Terminalist says:

    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 . . .

    Reply  |  Quote
  2. Luke UNITED STATES Mozilla Firefox Ubuntu Linux says:

    Heh. I definitely love my /proc goodies. ;P

    Reply  |  Quote
  3. Pingback: Terminally Incoherent » Blog Archive » How To Kill Stuff On Linux UNITED STATES WordPress

  4. polarizer GERMANY Mozilla Firefox Ubuntu Linux says:

    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

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *