# java关闭Process

java1.8之后，Process有了destroydestroyForcibly方法，用来结束进程，一般结束进程的流程为：

1. terminate process with destroy()
2. allow process to exit gracefully with reasonable timeout
3. kill it with destroyForcibly() if process is still alive

public Process destroyForcibly() {
destroy();
return this;
}


private static native boolean destroy0(long pid, long startTime, boolean forcibly);


Returns a snapshot of the current direct children of the process.The parent of a direct child process is the process.Typically, a process that is not alive has no children.

p.children().forEach(ProcessHandle::destroy);


Returns a snapshot of the descendants of the process.The descendants of a process are the children of the processplus the descendants of those children, recursively.Typically, a process that is not alive has no children.

ProcessHandle handle = p.toHandle();
handle.destroy();
handle.descendants().forEach(ProcessHandle::destroy);