Now, for your assignment, write a bash one liner or short script that finds and kills any process associated with Firefox.


  1. #1 Matthew Platte
    March 16, 2009

    This lives in ~/scripts and there’s a Gnome launcher in the top panel that activates it. I use it (too frequently) when ‘dobe Flash drives Firefox insane.

    kill -HUP `ps -aef | grep -i firefox | awk ‘{print $2}’`

  2. #2 peter
    March 16, 2009

    just curious, why use grep then awk, rather than just the awk filter?

    (this on mac terminal so ps has no ‘f’ arg)
    kill -9 `ps acx | awk ‘/Firefox/ {print $1}’ `

    though I suppose if the capital were the issue:
    kill -9 `ps acx | awk ‘/irefox/ {print $1}’ ` or
    kill -9 `ps acx | awk ‘/[Ff]irefox/ {print $1}’ `

  3. #3 Greg Laden
    March 16, 2009

    The process should always be all lower case.

    The auk filter is good. But, using grep in line after ps is one way of compartmentalizing the flow. So it could depend on what the larger scale objective is.

  4. #4 Jason Thibeault
    March 16, 2009

    What, is “killall firefox” insufficient? I suppose if you’re exercising the reader, or if /usr/bin/killall doesn’t exist on your distro…

  5. #5 Jason Thibeault
    March 16, 2009

    Actually, I retract my previous comment, on the grounds that people should learn to do things the hard way first, and that I couldn’t do my job day to day without grep and awk. I even installed Windows versions of those two commands on my DC.

  6. #6 Wayne Conrad
    March 16, 2009

    killall firefox-bin

    I’ll get marked down when I’m graded, because it doesn’t do exactly what the assignment asked for. For one thing, although it will kill the Firefox main process (which is called firefox-bin in Debian) and its children, any orphans will get left behind. But there are seldom, if ever orphans, so that hasn’t been a problem.

  7. #7 peter
    March 16, 2009

    could you define what you mean by “compartmentalizing the flow?”

    (btw, for what it’s worth, on mac os, GUI applications tend to be capitalized on mac os. (i.e. safari is “Safari”) or at least displayed as the finder knows them.)

  8. #8 Greg Laden
    March 16, 2009

    I mean when you are writing code and you have a series of steps some of which you change. I do this all the time. This is why I use cat to feed a stream to a process via pipe. All the other Linux people hate me but I don’t care.

    This discussion does not apply to Macs. This discussion is about when something goes wrong. I’m told that this does not happen on Macs. Is that not the case? Please, no, don’t let i be so! Don’t let it be so!

    (OK, sorry, I’m in a nasty mood this afternoon. Don’t be the guy in front of me on the highway exit who decides to clean out his freakin’ glove compartment instead of drive!!!! Or whatever.)

  9. #9 Beowulff
    March 16, 2009

    pkill firefox

  10. #10 Beowulff
    March 16, 2009

    Or if using grep is really mandatory:
    ps acx|grep firefox|cut -f1 -d” “|xargs kill

  11. #11 Greg Laden
    March 16, 2009

    Good point. Why use auk when you can use cut????????