gpt4 book ai didi

java-9 - 如何使用java 9杀死当前进程

转载 作者:行者123 更新时间:2023-12-02 03:41:52 35 4
gpt4 key购买 nike

我已尝试使用以下代码来使用 destroydestroyForcously -

ProcessHandle currentProcess = ProcessHandle.current();
System.out.println("current process id:"+currentProcess.getPid());
currentProcess.destroyForcibly();

但在两种情况下都会出现异常

Exception in thread "main" java.lang.IllegalStateException: destroy of current process not allowed at java.base/java.lang.ProcessHandleImpl.destroyProcess(ProcessHandleImpl.java:308) at java.base/java.lang.ProcessHandleImpl.destroyForcibly(ProcessHandleImpl.java:331) at util.CurrentProcess.main(CurrentProcess.java:18)

最佳答案

Javadoc on ProcessHandle::current说:

Returns a ProcessHandle for the current process. The ProcessHandle cannot be used to destroy the current process, use System.exit instead.

关于java-9 - 如何使用java 9杀死当前进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42736181/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com