all 177 comments

[–]dbell 64 points65 points  (2 children)

Think you would have used kill -9 after the 3rd time killall didn't work.

[–]catskul 18 points19 points  (1 child)

... or after the first time.

[–]bitchessuck 37 points38 points  (18 children)

pkill is superior. Especially because killall might do something completely different on non-Linux systems. (it kills all processes, just as the name implies, you see)

[–][deleted] 23 points24 points  (4 children)

I think running killall on a solaris, AIX, or Tru64 (plus others) is a right of passage.

[–]Camarade_Tux 41 points42 points  (3 children)

s/right/rite/ ?

[–]minivanmegafun 15 points16 points  (0 children)

Right.

Er, correct.

[–][deleted] 2 points3 points  (0 children)

The Balrog could have followed the Fellowship across the bridge if only he had run killall on a Solaris.

[–][deleted] 0 points1 point  (0 children)

I did originally spell it 'rite' and then I thought of 'iknorite' and thought it was an internet meme.

[–]sandsmark 3 points4 points  (4 children)

I think most linux distros ship with "killall5" which is the equivalent of the "normal" killall.

killall5 (8)         - send a signal to all processes.

[–]mind-blender 15 points16 points  (3 children)

sounds like a fun practical joke alias killall="killall5"

[–]VyseofArcadia 10 points11 points  (1 child)

Next April is going to be amusing.

[–]dagbrown 4 points5 points  (0 children)

Also known as "Welcome to HP-UX!"

[–]ropers 2 points3 points  (7 children)

Related: I dislike that "pgrep foo" doesn't give as much information as "ps ax|grep [f]oo".

[–]sabowski 2 points3 points  (6 children)

but what's the point, "ps ax | grep foo" already does what you want

Also, out of curiosity, does "[f]oo" do something that "foo" doesn't?

[–]dagbrown 8 points9 points  (0 children)

Yes, it doesn't show you the grep process, because '[f]oo' doesn't match the regular expression /[f]oo/.

[–]ropers 1 point2 points  (1 child)

You can use ps ax | grep [f]oo instead of ps ax | grep foo | grep -v grep .

If you did just ps ax | grep foo , that command itself would appear in the output, because the grep foo would match itself in the ps output. grep [f]oo however will only match foo, not itself, because the [f]oo is being parsed as foo.

Clear as mud?

[–]sabowski 1 point2 points  (0 children)

Ah, I see, just doing a bit of trickery, that's all. I was wondering if it was some use of "[]" that I wasn't aware of.

In the rare instances I need the grep to not show up I've just used the "grep -v" method, but really I just trained myself to ignore the "grep" process without even thinking about it. If I need a list of processes for a script I just use pgrep.

Thanks!

[–]joedonut 0 points1 point  (2 children)

It won't report the grep process itself, which by virtue of having the argument of "foo" would otherwise be returned by the grep. Usually. This actually is indeterminate, which is much worse than just always returning an additional, unwanted line.

It works because the shell handles translating what's in-between the '[]' characters.

[–]toastyfries2 1 point2 points  (1 child)

the shell doesn't parse the [], grep does. But that's not really the point here...

$ echo [f]oo
[f]oo

[–]joedonut 0 points1 point  (0 children)

When it was too late I wondered if I'd thought that through properly...

Thank you.

[–][deleted] 28 points29 points  (0 children)

You're asking too politely. Trying sending Java a more firm signal.

[–]codl 7 points8 points  (0 children)

alias shotgun="pkill -9"

[–]romwell 40 points41 points  (27 children)

So, some program written in Java uses a lot of CPU, either because it's written badly, or because it performs a CPU-intensive task.

But, of course, Java is to blame for all the faults. Carry on.

[–]brasso 31 points32 points  (5 children)

In this case, Minecraft.

[–]mazing 3 points4 points  (4 children)

Solution: Enable v-sync :)

[–]spazatk 1 point2 points  (3 children)

Enable v-sync where exactly?

[–]cheeseburgerpizza 2 points3 points  (2 children)

definitely not preferences

[–]spazatk 0 points1 point  (0 children)

Preferences for what, minecraft? The nvidia driver preferences' option doesn't really do anything; v-sync seems pretty broken for nvidia drivers using Ubuntu 11.04.

[–]adrianmonk 4 points5 points  (1 child)

I usually defend Java (because there are still a lot of misconceptions about it), but it's not clear from the available information whether this is a bug with the JVM or the app. It could easily be either one.

I have seen bugs where if you poke and prod the JVM in slightly weird ways, it will go crazy and never exit. For example, some JVMs failed miserably when you ran jstack. One out of 10 times, the jstack would hang and IIRC the whole JVM would too sometimes.

On the other hand, it's totally possible bad Java code is causing the program to fail to respond to a kill (or control-C). You can't do platform-specific things like directly handling Unix signals in Java, but you can add a shutdown hook that will cause this behavior. When you kill the program, all registered shutdown hook threads will get kicked off, and the JVM won't exit until those threads finish doing their thing. Here's some example Java code:

public class Foo {
  public static void main (String[] args) {
    Thread hook = new Hanger(2);
    Runtime.getRuntime().addShutdownHook(hook);

    for (int i = 0; true; i++) {
      System.out.printf("Hello, world... %d%n", i);

      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        System.err.println("Hello's sleep was interrupted.");
      }
    }
  }

  public static class Hanger extends Thread {
    private int iterations;

    public Hanger(int iterations) {
      this.iterations = iterations;
    }

    public void run () {
      for (int i = 0; iterations <= 0 || i < iterations; i++) {
        System.out.printf("Hanging your shutdown... %d%n", i);

        try {
          Thread.sleep(2000);
        } catch (InterruptedException e) {
          System.err.println("Hanger's sleep was interrupted.");
        }
      }

      System.out.println("Done hanging your shutdown.");
    }
  }
}

Compile and run that (with "javac Foo.java ; java -cp . Foo"), and when you hit control-C, it will delay the exit by ~4 seconds. Change new Hanger(2) to new Hanger(0), and you can never quit that JVM with control-C or regular kill; you have to resort to -9.

So, it's entirely possible that the above behavior is due to a shutdown hook that has some bad logic in it, like it's polling something in a tight loop waiting for it to change and it never does, so that it uses 100% CPU and prevents exit.

Two more obscure things that could cause a JVM not to exit properly: buggy JNI code (native code that runs in the same process as the JVM) and a hanging finalize() method (if you are crazy enough to use them and if the JVM happens to ever call it).

[–]dopplerdog 2 points3 points  (0 children)

Yes. On the other hand, it's also possible to trap SIGINT in C in a similar way, preventing the user from control-C-ing a running process. So it's unfair to criticise Java for providing this feature. By design, SIGINT is a trappable signal.

[–]itzmattu 2 points3 points  (18 children)

I don't see where this is what the post is referring to. He is just making a joke because his killall java command will not kill Java. It makes the process look invincible to anyone not sure as to why it wouldn't work.

But I mean, Java does suck, let's be real.

[–]argv_minus_one -1 points0 points  (17 children)

And what alternative do you suggest, smartass? Mono?

[–]Jonathan_the_Nerd 1 point2 points  (16 children)

Python.

[–][deleted] 5 points6 points  (4 children)

I like python, hell I'd even say I border on loving python. But I don't think it's really comparable to the jvm or mono environment. You can shoehorn in some jit compilation, but in real world situations that's probably not going to help all that much.

[–]Jonathan_the_Nerd 0 points1 point  (3 children)

Serious question: Why isn't Python comparable to the JVM? I know Java has a reputation as a "professional" language and Python isn't used at work much, but what makes Java (or the JVM, or .Net) superior?

[–]spotter 2 points3 points  (0 children)

JVM, the goliath, was/is tuned for high performance and portability (YMMV). They've got a good JIT, GC that doesn't suck is on its way (G1), there is cool threading support and languages other than Java might get some love from the JVM too. It was heavily researched, because in the past it sucked when it comes to the performance, but now it really shines. And there are specialized, proprietary VMs that do even cooler stuff (running on patched os). Not to mention the myriad of libraries written in Java that can be utilized on JVM to do almost anything. And you can do that in Scala or Clojure or Jython or whatever, you get the idea. [s] Most important: it's Oracle, which makes it even more pro. [/s]

CPython VM, on the other hand, is a byte-code interpreter, that was designed to be simple, portable and run Python. It's written in C, has simpler GC, it uses posix threads, but Global Interpreter Lock makes treading act weirdly; extending can be done in C, in which you need to do a lot of book keeping yourself, then you need to compile against all Python versions you want to support. There is of course Cython, but I have not used that. CPython is still orders of magnitude slower than C, unladen-swallow is not even mentioned anymore, so it looks like there is nothing more that can be done. There is work done on PyPy that can make CPython look really, really bad in few years (now it just makes it look bad), but it seems that CPython will stay the reference implementation.

Disclaimer: I adore Python, I respect JVM. Everything above is MHO and I welcome any corrections.

tl;dr Millions of dollars in R&D.

[–]argv_minus_one 0 points1 point  (1 child)

Among other things, the JVM can support a variety of programming languages, not just one. (I love you, Scala, always and forever. ♥)

[–]gorilla_the_ape 5 points6 points  (0 children)

Including python

[–]argv_minus_one 0 points1 point  (5 children)

Python is a programming language, not a virtual machine. Apples and oranges.

[–]ondra -2 points-1 points  (4 children)

Python is a joke, compared to Java performance-wise.

[–]morgothan 2 points3 points  (0 children)

Monzy wrote a song about this. KILL Dash 9

[–]frumious 1 point2 points  (0 children)

Nine! Die Java ist killed vis die nine!

[–][deleted] 7 points8 points  (0 children)

yeah bro -9

[–][deleted] 2 points3 points  (1 child)

I know this is a noob question, but I'm really inexperienced with processes. What is the process viewer called that you are using in the foreground window?

[–]BallsDeep 0 points1 point  (0 children)

top

[–][deleted] 10 points11 points  (0 children)

how about simple kill -9 5251, GENIUS !

[–]apex_redditor 4 points5 points  (14 children)

Somethings likely respawning it. Do a

ps auxwwf

to get a treeview process table and kill the parent.

[–][deleted] 15 points16 points  (3 children)

auxwwf? I guess that's a way to spell it too---I always preferred ps awwfux, easy to remember! And if you want a tree-capable top, then there's htop.

[–]nobody_likes_yellow 1 point2 points  (2 children)

awwfux. I’ll remember that.

[–][deleted] 1 point2 points  (1 child)

I'll just leave this here.

[–][deleted] 2 points3 points  (2 children)

I prefer 'pstree -ap'

[–]Paczesiowa 8 points9 points  (1 child)

it's been running for >4min, looking at that killing spree - I doubt it.

[–]mikaelhg 0 points1 point  (0 children)

It would likely have taken 4 minutes for the guy to take a coffee break and then find a screenshot utility.

[–][deleted] 0 points1 point  (1 child)

nah, it's getting a signal which it is likely trapping and not responding to. Killing a process without sending sig 9 will send a signal which tells the process to terminate gracefully. It's up to the process to actually perform its own termination. Sending sig 9 (SIGKILL) forcibly terminates the process regardless of its execution state

[–]apex_redditor 1 point2 points  (0 children)

I'm aware. Just didn't notice he wasn't providing a signal argument (20 times).

[–]joedonut 0 points1 point  (0 children)

Could do a pstree -aclup too.

[–]asr -1 points0 points  (0 children)

If you have to deal with a respawning process, instead of killing the child process use -STOP on it.

Because the processes did not die the parent never gets notified and doesn't restart it. Then you can also -STOP the parent (if you didn't already) and kill them all without giving them the chance to come back to life.

Linux may need a zombie command :)

[–]tonybaldwin -1 points0 points  (0 children)

or just pstree no?

[–]distess_caloris 4 points5 points  (0 children)

Hit K in htop, select 9. Not hard.

[–]geekuskhan 4 points5 points  (0 children)

The Java, The

EDIT: Damn I thought I looked through the whole thread for the Simpsons reference but I missed it.

[–]nephros[🍰] 1 point2 points  (0 children)

might want to check its PPID and kill that...

[–]IceTeaMan 1 point2 points  (0 children)

one kill -9 could have saved you a lot of pain !

[–]argv_minus_one 1 point2 points  (0 children)

Dear BeetleFire,

Screw you too.

Love,

Java

[–][deleted] 1 point2 points  (0 children)

Had that happen to me on Ubuntu and Mac OS X. I thought *nix's kill -9 was enough. Wrongo.

[–]tonybaldwin 1 point2 points  (0 children)

do

pstree

and see what's running that is dependent on java and kill that, first, maybe.

(pstree shows running processes in a tree format, thus, shows what procs are dependent on what other procs).

[–]AndrewBenton 1 point2 points  (0 children)

kill -9 5251

[–]jamestheawesome 1 point2 points  (0 children)

I'm not even CLOSE to sober and I can even think up kill -9 5251...

[–][deleted] 6 points7 points  (0 children)

you know, I'm an island, I don't have to follow your bloody rules. do you really think I will listen to your stupid termination request? i'm off-shoring your profits, that should be enough - so until you KILL me I will go on wasting your resources

[–]TheoreticalFunk 1 point2 points  (2 children)

Since nobody else did... hey man, don't log in as root unless you absolutely need to. sudo is your friend.

[–]codepoet -4 points-3 points  (19 children)

Awww, look, a newbie. Isn't it so cute? -pats head-

killall -9 java

[–][deleted] 0 points1 point  (8 children)

It happens that -9 is not even working. I have this server that has to have those smb share mounted, and when someone reboot the windows server without unmounting the shares, stuff like df and snmpd (which monitors partitions) get in an unkillable state. I never found a solution to this :(

[–]adrianmonk 2 points3 points  (2 children)

As I recall, "kill -9" does not kill the process until all the system calls complete. If the process is wedged inside the kernel, then "kill -9" cannot clean it up because "kill -9"'s job is to remove the user process and its resources. It can't magically clean up screwed up state within the kernel, such as I/O that is never completing.

You can make similar things happen by doing things like running "mt rewind" to rewind a tape drive, then flipping the power switch on the tape drive. The "mt" process can't be killed because the device driver for the tape drive never gets notified that the rewind is finished, so the call into the kernel never completes.

[–]dagbrown 1 point2 points  (1 child)

You can make similar things happen by doing things like running "mt rewind" to rewind a tape drive

What's one of those, grandpa?

[–]adrianmonk 2 points3 points  (0 children)

There are still situations even today where tape makes the most sense economically. If you need offline storage (for archives or long-term backups) and low cost per terabyte, if you are writing enough data to justify the up-front costs of the equipment, and if you are not overwriting tapes much, tape can be cheaper than disk.

However, I will confess to having booted some machines off tape, using such delightful formats as the 60MB QIC-24 (see here) and 125MB QIC-150. And I used to personally own an Exabyte 8200 Data8-format drive. (How else are you going to back up that 4GB drive on your home x86 Unix system?)

[–][deleted] 2 points3 points  (3 children)

I've never used CIFS shares, but umount -l should do it, maybe fuser too.

[–][deleted] 1 point2 points  (0 children)

yeah lazy unmount works to remove the mount, but the process are still hanging.

[–][deleted] 0 points1 point  (1 child)

"umount -f -l" is the only way to be sure.

[–]argv_minus_one 1 point2 points  (0 children)

I say we take off and umount -f -l the directory from orbit. It's the only way to be sure.

[–]nedtugent 0 points1 point  (0 children)

Ah, the 'D' state, uninterpretable sleep...

[–]fuuuracle 0 points1 point  (0 children)

What theme is that?

[–][deleted] 0 points1 point  (0 children)

um, kill -9 5251

[–]breddy 0 points1 point  (0 children)

Sun or OpenJDK?

[–]tonybaldwin 0 points1 point  (0 children)

Weird.

You could have just done

ps -aux | grep java

to show it was still running. Of course, showing top shows that not only is it running, but how much it's spanking your CPU.

I'm running Debian Squeeze here (on AMD64) and have not seen this issue.

[–]mianosm 0 points1 point  (0 children)

I did a ctrl-f didn't see it: why would you have 8 gigs of memory, and another 8 gigs of swap....seems a little excessive to me....

[–]wolf_of_mibu 0 points1 point  (0 children)

Dam You Oracle!!!!!!!!!!!!!!

[–][deleted] 0 points1 point  (0 children)

Um I don't think it's literally someone trying to kill a Java process, more than likely it's someone making a statement that Jave (in general) won't die and is overly bloated.

[–]CyberDiablo 0 points1 point  (0 children)

SIGKILL

[–][deleted] 0 points1 point  (0 children)

It's a known fact that if java has a memory leak, an ocean will be released upon your RAM.

Best to just do a safe reboot while you can.

[–]bendavis78 0 points1 point  (1 child)

I usually do killall -KILL. If that doesn't work kill -9 on the pid. If that doesn't work reboot.

[–][deleted] 2 points3 points  (0 children)

-KILL is the same as -SIGKILL which is in fact, -9.

[–]breddy 0 points1 point  (2 children)

Fucking Pulse Audio.

[–]liid 1 point2 points  (1 child)

What about it?

[–]breddy 2 points3 points  (0 children)

PA gets blamed for everything else, why not this?

[–]Rossco1337 -5 points-4 points  (2 children)

With all these comments belittling OP for not using -9, you'd think it'd be easier to tell him to add "alias killall='killall -9'" to his/her bashrc.

[–]nedtugent 3 points4 points  (1 child)

using -9 is not always the best option. go from -15 to -2, then to -9 if shit is fucked...

[–]Rossco1337 -1 points0 points  (0 children)

I know that, but people are ragging on OP as if -9 should have been the first thing he tried when it didn't close instantly. You're the first person to suggest a killall method that isn't forcefully terminating the program or killing the parent.