Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any VM supporting Process.supportsNormalTermination==true?

Tags:

A new feature of Java 9 is that it can not only forcefully kill processes (in the meaning of SIGKILL) it had created but it may also support to send a SIGTERM (in Java called "normal termination").

According to the documentation of Process one can query if the implementation supports this:

public boolean supportsNormalTermination​() Returns true if the implementation of destroy() is to normally terminate the process, Returns false if the implementation of destroy forcibly and immediately terminates the process. Invoking this method on Process objects returned by ProcessBuilder.start() and Runtime.exec(java.lang.String) return true or false depending on the platform implementation.

I made some tests using Oracle JRE 9.0.1 (Windows 64bit):

Process p = Runtime.getRuntime().exec("javaw -cp target/classes TestClassWait10Minutes");
p.waitFor(5, TimeUnit.SECONDS);
System.out.println(p.supportsNormalTermination());

However it seems like Oracle JRE does not supports "normal termination" as I always get false.

As it depends on the "platform implementation" it seems that Java 9 defines it but does not implement it.

Does anybody know if the feature of "normal termination" is usable at all in any available Java VM?

like image 223
JMax Avatar asked Nov 13 '17 14:11

JMax


1 Answers

On Linux implementation, it seems to support normal termination. From the source of ProcessImpl:

// Linux platforms support a normal (non-forcible) kill signal.
static final boolean SUPPORTS_NORMAL_TERMINATION = true;

...

@Override

public boolean supportsNormalTermination() {
    return ProcessImpl.SUPPORTS_NORMAL_TERMINATION;
}

Not the case on Windows.

like image 121
M A Avatar answered Oct 13 '22 20:10

M A