Cannot kill a java process

6,168

It's rare but possible for processes to end up in a D (uninterrupted sleep) state and they cannot be killed. You can check with:

ps -o cmd,stat -p <pid>

If the STAT is D, that's the issue.

If not I suggest you add some more information to your post such as exactly what the process is, what it is doing, and why you want to kill it.

Share:
6,168

Related videos on Youtube

Howard Stark
Author by

Howard Stark

Updated on September 18, 2022

Comments

  • Howard Stark
    Howard Stark over 1 year

    I have a java process that cannot be killed. I have tried every method I know, or that I have found on the internet to no avail. I have tried:

    killall java
    kill -9 <pid>
    kill -11 <pid>
    kill -6 <pid> 
    

    No matter what I try, I cannot kill the program. If this helps, it has a dynamic PID, and this has happened before and I somehow killed it last time.

    • amphibient
      amphibient over 11 years
      are you sure you are using the correct PID?
    • Marco
      Marco over 11 years
      Are you sure the program is still alive and not a zombie? BTW: There is usually no reason to kill -9 a process. Sending a SIGTERM, then SIGQUIT or SIGINT should make the program quit. If it doesn't it's buggy.
    • tink
      tink over 11 years
      It's also worth noting that it's often impossible to kill processes that are currently waiting on I/O.
    • goldilocks
      goldilocks over 11 years
      Disagree with Marco about the use value of SIGKILL and the assertion that a program that responds to that but not SIGTERM is "buggy". $0.02
    • Marco
      Marco over 11 years
      @goldilocks A program cannot respond to SIGKILL. Usually you want to give the program a change to clean up (close files, network connections, etc) and then exit and that's what SIGTERM is for. If you tell a program to terminate and it refuses, it's a bug! SIGINT or SIGQUIT should not be necessary, but some programs respond to the signals and exit immediately. SIGKILL is only useful if you want to prevent the program from cleaning up or in the rare case it got stuck in the clean-up code.
    • goldilocks
      goldilocks over 11 years
      @Marco I am aware of how signal handling works, and the fact that "a program cannot respond to SIGKILL" is the use-value I was referring to. If SIGTERM does not work, use SIGKILL. The fact that a process hangs in clean-up on an arbitrary SIGTERM may or may not be evidence of a bug in that program -- it may also be due to explicit mis-use, problems with the system (IO), or a problem/bug in a shared component. Not responding to SIGTERM is not a good sign, but signs like that could be considered a feature as opposed to a bug, depending on the context.
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' over 11 years
      What is the output of ps l 1234 where 1234 is the process ID?
    • manatwork
      manatwork over 11 years
      I have a Java program which occasionally gets immune to SIGKILL. In such cases I send it to background with Ctrl-Z when kill -9 %1 works.