我已经尝试了两者destroy
并destroyForcibly
使用以下代码-
ProcessHandle currentProcess = ProcessHandle.current();
System.out.println("current process id:"+currentProcess.getPid());
currentProcess.destroyForcibly();
但是在两种情况下都例外
线程“主”中的异常java.lang.IllegalStateException:在java.base / java.lang.ProcessHandleImpl.destroyForcably(在java.base / java.lang.ProcessHandleImpl.destroyProcess(ProcessHandleImpl.java:308)上不允许破坏当前进程util.CurrentProcess.main处的ProcessHandleImpl.java:331)(CurrentProcess.java:18)
Javadoc上ProcessHandle::current
说:
返回
ProcessHandle
当前进程的。将ProcessHandle
不能被用来破坏当前进程,使用System.exit
代替。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句