Tuesday, April 5, 2011

How can I kill all shells in Unix at once?

My Mac becomes slow over time. The reason is the huge amount of my shells, such as Bashes and Fishes. Each shell has different PID. Killing shells one by one is too cumbersome. How can I kill them at once?

From stackoverflow
  • The killall command can kill all processes with a given name:

    killall bash
    
    Jonathan Leffler : Doesn't this endanger the shell from which it is run?
    dmckee : Also, this is linux specific. Older unixies had differnet symantics for "killall".
    dmckee : Um. Actuall it works in Mac OS X as well.
    Robert Gamble : @Jonathan: Yes, if the shell the example is run from is a bash shell then it will be killed as well, from the question this appears to be the desired behavior.
    dmckee : "appears to be the desired behavior": at least it is the one he asked for...which is not always what is actually desired...
    Jonathan Leffler : @Robert: I guess "be careful what you ask for; you might get it" is roughly what applies. The caveat has now been given to the questioner by these comments. :D
  • Know the filename of the executable? You can use "killall " on many Unix systems.

    # killall <name>
    
  • Try 'killall bash' or 'killall -9 bash' if they resist that.

  • As per other answers, the usual command is killall.

    Note though that on some versions of UNIX (e.g. DEC Unix) this command literally kills all processes.

    Do make sure that you know which behaviour your UNIX has before using it!

    Masi : Where are the codes for killall and kill in my comp for inspection?
    Keltia : kill -l generally lists all signals.
    dmckee : HL, have you considered just reading `man killall`?
    Dave C : @Keltia, signals and kill(1) are completely irrelevant to this question/answer.
  • I think that you cannot kill all your Shells at once. You have to use many killalls, separately to each Shell like Rjamestaylor says above:

    killall bash
    killall fish
    

    And so on.

    Ben Blank : Well, if you're executing this from a bash shell (the default on OS X), you'll want to run those two commands in the opposite order. :-)
  • I strongly doubt your initial diagnosis. In Unix, an inactive process does not take resources. It is not scheduled, its memory is swapped out, etc. If there is a problem of slowness, it probably has another cause. Running top is the first step.

    Masi : The Fish shell, probably a beta, consumes almost all of my CPU. It is shame as Fish is easy to use. I like the colours.

0 comments:

Post a Comment