saker.util Documentation TaskDoc JavaDoc Packages
public class ProcessUtils
Utility class containing functions regarding process manipulation.
Methods
public static void
Destroys a process and possibly all of its spawned child processes.
public static Integer
Gets the exit code of the argument process, if it has exited.
Destroys a process and possibly all of its spawned child processes.

Important: This method works differently on different JRE versions.

On JDK 8, this will simply call Process.destroy(). Child processes spawned by the process are not affected.

On JDK 9 and later, this will retrieve the process handle, and destroy the process itself and the children too, recursively.
The process handle API was introduced in JDK 9. Using it the spawned children can be retrieved from a process, and iteratively destroyed. The destruction is done by querying if the process supports normal termination, and if so, destroy() will be called on them. If they don't support normal termination, or the destroy() call returned false, destroyForcibly() will be called on them.

This function should be considered as a last resort for destroying a process. Callers are strongly recommended to make sure that the process is exited cleanly by using some interprocess communication methods.

pThe process to destroy.
Gets the exit code of the argument process, if it has exited.
pThe process.
The exit code, or null if it has not yet terminated.