If you want to kill all processes that are named java you can use following command:

killall -9 java

This command sends signals to processes identified by their name.

Answer from Milan Todorovic on askubuntu.com
🌐
CircleCI
discuss.circleci.com › build environment
Java process killed with no info as to why - Build Environment - CircleCI Discuss
August 24, 2018 - I have a series of scripts that I run as a workflow job, and one of those scripts requires a jar to be executed, however CircleCI is for some reason killing the java task/process a few seconds into its execution. The log tells me ./scripts/remap.sh: line 79: 377 Killed java -jar "$workdir/BuildData/bin/SpecialSource-2.jar" map -i "$jarpath.jar" -m "$classmappings" -o "$jarpath-cl.jar" My config is currently: # Java Maven CircleCI 2.0 configuration file # # Check https://circleci.com/docs/2.0...
Discussions

process management - 'kill java' doesn't kill java - Unix & Linux Stack Exchange
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 More on unix.stackexchange.com
🌐 unix.stackexchange.com
August 18, 2010
Something keeps killing my Java process on Ubuntu, anyone know why? - Stack Overflow
So every couple of days my java process on Ubuntu is killed automatically, and I can't figure out why. My box has 35.84 GB of RAM, when I launch my Java process I pass it the -Xmx28g parameter, so... More on stackoverflow.com
🌐 stackoverflow.com
Kill only one Java process - Unix & Linux Stack Exchange
I usually run few Java applications, one for server running locally and other for some IDE like NetBeans. And from time to time, after lots of redeployments, my server get stuck on OutOfMemoryExcep... More on unix.stackexchange.com
🌐 unix.stackexchange.com
Killing a process using Java - Stack Overflow
I would like to know how to "kill" a process that has started up. I am aware of the Process API, but I am not sure, If I can use that to "kill" an already running process, such as firefox.exe etc. ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › netikras › 16-killed-java-jvmopts-jar-app-jar-3clk
16 Killed java $JVM_OPTS -jar app.jar - DEV Community
April 6, 2021 - This is the most likely cause of your outages. If you have accesses, you can confirm this theory by examining the last entries in the dmesg output. If you see the 'Killed process 4832 (java)' entry there along with some memory layout tables then you've got your killer.
Top answer
1 of 5
9

Assuming the problem is the OOM killer, then it has killed your process in a desperate attempt to keep the OS functioning in a severe memory shortage crisis.

I would conclude that:

  • your JVM is actually using significantly more than 28Gb; i.e. you've got significant non-heap memory usage, and

  • the OS is not configured with an adequate amount of swap space.

I'd try adding more swap space, so that the OS can swap out parts of your application in an emergency.

Alternatively, reduce the JVM's heap size.


Note that "-Xmx ..." sets the maximum heap size, not the maximum amount of memory that your JVM can use. The JVM puts some stuff outside the heap, including such things as the memory for thread stacks and memory-mapped files that your application is using.


The syslog confirms that it is the OOM killer at work.

In what way does the linked syslog say so?

It says this:

Nov 15 13:53:49 ip-10-71-94-36 kernel: [3707038.606133] Out of memory: kill process 6368 (run.sh) score 4747288 or a child
Nov 15 13:53:49 ip-10-71-94-36 kernel: [3707038.606146] Killed process 9359 (java)

The console says that java was killed, not that it quit.

Correct. It was killed by the operating system's OOM killer.

If it had run out of memory it would typically throw an OutOfMemory exception, which it didn't.

That is what would have happened if you had filled up the Java heap.

That is not what is going on here. The actual problem is that there is not enough physical RAM to hold the Java heap. The OOM killer deals with it ...

I'm running with such a huge heap because I need to store millions of objects each of which require several kilobytes of RAM.

Unfortunately, you are trying to use way more RAM than is available on the system. This is causing virtual memory to thrash, affecting the entire operating system.

When the system starts to thrash badly, the OOM killer (not the JVM) identifies your Java process as the cause of the problem. It then kills it (with a SIGKILL) to protect the rest of the system. If it didn't, there is a risk that the entire system would lock up completely and need to be hard rebooted.


Finally, you said:

My box has 35.84 GB of RAM ...

That is rather a strange value. 32 GiB is 34,359,738,368 bytes or 34.35 GB.

But based on that and the observed behavior, I suspect that that is the available virtual memory rather than physical RAM. Alternatively, your "box" could be a virtual machine with RAM overcommit enabled at the hypervisor level.

2 of 5
7

Welcome to the OOM-killer, a linux 'feature' that is the bane of large-memory applications everywhere. There's no simple recipe to deal, just google for it and start reading and weaping.

While I can't put my mental fingers on a concise explanation of the shenigans of the OOM killer, I recall that the critical tuning parameter is called 'swappiness'. On one of our big servers, we have:

/etc/sysctl.conf:vm.swappiness=20

Read http://www.gentooexperimental.org/~patrick/weblog/archives/2009-11.html.

🌐
GitHub
github.com › JDASoftwareGroup › graceful-kill-java
GitHub - JDASoftwareGroup/graceful-kill-java: Graceful-kill-java allows you to gracefully kill java processes on Windows, which 'taskkill pid' and 'wmic ... call terminate' cannot do.
Graceful-kill-java allows you to gracefully kill java processes on Windows, which 'taskkill pid' and 'wmic ... call terminate' cannot do. - JDASoftwareGroup/graceful-kill-java
Forked by 3 users
Languages   Java 81.3% | Batchfile 18.7% | Java 81.3% | Batchfile 18.7%
Find elsewhere
🌐
Coderanch
coderanch.com › t › 529177 › java › JVM-Behaviour-Kill-JAVA-Process
JVM Behaviour- Kill JAVA Process (Java in General forum at Coderanch)
March 2, 2011 - When you kill it, you kill it. Nothing will be done after that point. It sounds like your program reaches deadlock. I'm guessing this is because you're making changes to your GUI from another thread than the Event Dispatch Thread (EDT). Put a few println statements in your program to identify where it hangs, and then post that part, and we can have a look at it. ... And run it from the command line using java -jar.
Top answer
1 of 2
1

As waltinator suggested in the comment to you question, you can run your process with a shell script. That script can block waiting for your process to terminate, then inspect the exit status to get some idea of the failure mode.

Generally if a process is terminated by a signal, the exist status is 128 plus the signal number. For example, if someone did a kill -9 on the process, then the exit status would be 137 (128 + 9 = 137).

For example, here's a script that runs your command and prints a message if it terminated in response to a signal:

#!/bin/bash

$JAVA_HOME/bin/java \
    -verbose \
    -classpath '../../lib/*:.:./config' com.xxx.xxx.core.xxxxApp instance:$INSTANCE

rc=$? # The $? variable has the exit status of the previous command


if [[ ${rc} -gt 128 ]]; then
    printf "Process terminated with signal %d\n" $((rc - 128))
fi

Now, if I use kill -9 to terminate the java process, then I get:

Process terminated with signal 9
2 of 2
0

It seems kernel is killing the process due to some problems, for example if a process is consuming too much memory then the kernel Out of Memory (OOM) killer will automatically kill the offending process. You can make sure by checking logs for any kernel related error logs:

egrep -i 'killed process' /var/log/messages

or

egrep -i -r 'killed process' /var/log

I suggest to check system logs and see the logs related to the process of java program you are executing.

dmesg | grep -i kill

This one for example displays logs related to kill to check full logs you can use:

dmesg | less

system logs give you detailed information why the process is killed is it memory issue or any other.

If someone is killing this process there needs to be super user you can check /var/log/auth.log for kill command

🌐
YouTube
youtube.com › watch
How Microsoft Killed Java — And Paid $2 Billion to Hide What It Did - YouTube
Microsoft's internal memo said it plainly: "Kill cross platform Java by growing the polluted Java market." In 1998, the company with 82% market dominance did...
Published   June 3, 2026
🌐
Heaphero
blog.heaphero.io › home › how to solve outofmemoryerror: kill process or sacrifice child
Java OutOfMemoryError: Kill Process or Sacrifice Child
December 26, 2025 - When there is a lack of RAM capacity in the container/device, the kernel will terminate the memory consuming processes to free up the RAM. If that terminated process turns out to be a Java application, it will result in ‘java.lang.OutOfMemoryError: Kill process (java) or sacrifice child’.
🌐
Mastertheboss
mastertheboss.com › home › java › how to kill a java process from java
How to kill a Java process from Java - Mastertheboss
July 17, 2021 - import java.io.BufferedReader; import java.io.InputStreamReader; public class Execute { public static void main(String[] args) { String s = new Execute().executeCommand("netstat -tulpn", "127.0.0.1:8080"); System.out.println(s); int left = s.indexOf("LISTEN"); int right = s.indexOf("/java"); String process = s.substring(left + 6, right).trim(); String sp = new Execute().executeCommand("ps -ef", process); System.out.println(sp); String spkill = new Execute().executeCommand("kill -9 " + i, process); } private String executeCommand(String command, String grep) { StringBuffer output = new StringBu