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.

Related Posts:

  • How To Kill Stuff On Linux
  • Katapult: Launchy/Quicksilver for Linux
  • Which OS is more User Friendly and Intuitive?
  • Local Privileges Escalation in WinXP
  • Linux: Quick and Dirty Way to Take Screenshots
  • How to find out the version of your OS
  • Adding new column to a text file
  • Easy Way to Create Simple Linux Packages
  • The Denoobization Script
  • Screen Mnemonics

  • 4 Responses to “Pkill - an Easier Linux Kill Command”

    1. Gravatar Craig Betts UNITED STATES Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.5 on Solaris Solaris
    2. Gravatar Luke UNITED STATES Says: Reply to this comment

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

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.2 on Ubuntu Linux Ubuntu Linux
    3. Gravatar Terminally Incoherent » Blog Archive » How To Kill Stuff On Linux UNITED STATES Says: Reply to this comment

      […] 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 using WordPress WordPress 2.0.5
    4. Gravatar polarizer GERMANY Says: Reply to this comment

      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 Mozilla Firefox Mozilla Firefox 2.0.0.6 on Ubuntu Linux Ubuntu Linux

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <pre lang=""> <em> <i> <strike> <strong>

    [Quote selected]