The new ProcessHandle interface
There are two new interfaces and also their implementations in Java 9 supporting the handling of operating system processes. One of them is ProcessHandle
, the other one is ProcessHandle.Info
, a nested interface of the prior.
A ProcessHandle
object identifies an operating system process and provides methods to manage the process. In prior versions of Java, this was possible only using operating system specific methods using the PID to identify the process. The major problem with this approach is that the PID is unique only while the process is active. When a process finishes, the operating system is free to reuse the PID for a new process. When we know only the PID of a process and check to see if the process is still running, what we are really doing is checking if there is an active process with that PID. Our process may be alive when we check it, but the next time our program queries the process state, it might be a different process.
The desktop and server...