Just triggering the process as you do will very likely get stuck. This is not directly related to Java but how operating systems treat processes if their streams are not handled (see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Process.html).
So once you start a process, wait until it finishes. While waiting, ensure its stdout and stderr streams are cleared so the OS will not block the process.
While this answer does not tell you why sometimes processes get killed and sometimes not, I am sure once you try this there is enough information in your java output so you can figure it out.
The code could look something like this:
Process process = Runtime.getRuntime().exec(cmd);
InputStream pin = process.getInputStream();
InputStream perr = process.getErrorStream();
byte[] buffer = new byte[4096];
int read = 0;
while (process.isAlive()) {
read = pin.read(buffer); // empty stdout so process can run
if (read > 0) {
System.out.write(buffer, 0, read);
}
read = perr.read(buffer); // empty stderr so process can run
if (read > 0) {
System.err.write(buffer, 0, read);
}
}
// empty buffers one last time
read = pin.read(buffer);
while (read >= 0) {
System.out.write(buffer, 0, read);
read = pin.read(buffer);
}
read = perr.read(buffer);
while (read >= 0) {
System.err.write(buffer, 0, read);
read = perr.read(buffer);
}
// print process exit code
System.out.println("exited with "+process.getExitValue());