任何支持 Process.supportsNormalTermination==true 的虚拟机?
Any VM supporting Process.supportsNormalTermination==true?
Java9的一个新特性是它不仅可以强制杀死它创建的进程(SIGKILL
的意思)而且它还支持发送一个SIGTERM
(在 Java 中称为 "normal termination")。
根据 Process 的文档,可以查询实现是否支持这一点:
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.
我使用 Oracle JRE 9.0.1(Windows 64 位)进行了一些测试:
Process p = Runtime.getRuntime().exec("javaw -cp target/classes TestClassWait10Minutes");
p.waitFor(5, TimeUnit.SECONDS);
System.out.println(p.supportsNormalTermination());
然而,Oracle JRE 似乎不支持 "normal termination",因为我总是得到 false
。
因为它依赖于 "platform implementation" 似乎 Java 9 定义了它但没有实现它。
有人知道 "normal termination" 的功能是否可以在任何可用的 Java VM 中使用吗?
关于Linux实现,好像支持正常终止。来自 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;
}
Windows 不是这种情况。
Java9的一个新特性是它不仅可以强制杀死它创建的进程(SIGKILL
的意思)而且它还支持发送一个SIGTERM
(在 Java 中称为 "normal termination")。
根据 Process 的文档,可以查询实现是否支持这一点:
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.
我使用 Oracle JRE 9.0.1(Windows 64 位)进行了一些测试:
Process p = Runtime.getRuntime().exec("javaw -cp target/classes TestClassWait10Minutes");
p.waitFor(5, TimeUnit.SECONDS);
System.out.println(p.supportsNormalTermination());
然而,Oracle JRE 似乎不支持 "normal termination",因为我总是得到 false
。
因为它依赖于 "platform implementation" 似乎 Java 9 定义了它但没有实现它。
有人知道 "normal termination" 的功能是否可以在任何可用的 Java VM 中使用吗?
关于Linux实现,好像支持正常终止。来自 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;
}
Windows 不是这种情况。