8

I am running debian right now and sometimes I need to kill java manually from the terminal, but when I try kill #pid# or pkill java nothing happens. No console output (ok, that's normal) and java is still running (not normal). The only way to kill it is to restart the PC. Any suggestions?

1
  • what you are looking for is killall java Oct 21, 2019 at 11:39

6 Answers 6

16

Maybe its ignoring the signal for some reason. Did you try kill -9?

But please note: kill -9 cannot be ignored or trapped. If a process sees signal 9, it has no choice but to die. It can't do anything else - not even gracefully clean up its files.

1
  • 2
    kill -9 is generally a last resort. It's better to try kill -11 then kill -6 first. If kill -11 doesn't kill it, kill -6 usually does. Try kill -11 first, wait a few/several seconds, and if the process is still alive, try kill -6. Wait several seconds and if it still isn't dead, you can then try kill -9.
    – laebshade
    Dec 28, 2012 at 22:01
2

I occasionally have to kill -9. However, if this is happening regularly, you should fix the issue that is causing it. Kill -9 means something is way off.

In general, I only see this happen when you get yourself into serious memory thrash mode, which means you either need more system memory, or you're giving java too much memory when you start. More commonly, though, especially if you're developing stuff, you can see this when you run out of "PermGen" memory.

http://www.brokenbuild.com/blog/2006/08/04/java-jvm-gc-permgen-and-memory-options/

In any case, it may be due to OutOfMemory errors of some sort.

2
  • i think that is it. i havent tried it yet, but my machine on which the problem is, has 1GB Ram and java is allocating 512 MB.
    – Simiil
    Aug 19, 2010 at 6:43
  • 1
    (Loooong delay on this comment...) If you're developing Java, 1 Gig of ram is pretty much not going to cut it. Bite the bullet and upgrade to at least 2, shoot for 4+.
    – kāgii
    Sep 2, 2010 at 13:45
1

This should work:

killall -9 java
3
  • this is actually correct ans. please put your comment if downvoting. Oct 21, 2019 at 11:40
  • @JohnMiliter please don't break a correct answer. I've rolled back your edit Aug 16, 2021 at 7:29
  • 1
    @roottraveller it’s not correct, the case is significant (I’ll fix that). Aug 16, 2021 at 9:01
0

Read this, this and this . It will help you understand how kill command works.

You can search for the java pid with:

pgrep -l java or pidof java

Maybe you have zombie processes on the system, in that case read here

0

For me as soon as I killed the process, it would relaunch. So for me it was a fact finding mission involving the below commands. Assuming the relevant port is port 8080:

lsof -i tcp:8080

Note the process named java near the bottom and it's pid.

Then ps -ef <pid here>

This spit out a large message relating to tomcat. tomcat@9 in particular.

brew services stop tomcat@9 solved the issue

-1

Try this:

kill -9 $(pgrep Java)

pgrep returns the PID of the process named "Java", and kill kills it

1
  • 1
    This should be essentially the same as pkill, which is what he's already using Dec 29, 2012 at 2:39

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .