Java has improved the Process API in the Java 9 version, which can help manage and control operating system processes. In earlier versions, it was difficult to manage and control operating system processes using Java. Now, in Java 9 new classes and interfaces have been added to perform this task. ProcessHandle The interface is used to identify and control the local process, and provides methods to check process survivability and destroy the process. ProcessHandle.Info The interface provides an information snapshot of the process.
Process API Provides more information, such as:
public class ProcessTest { public static void main(String args[]) { <strong>ProcessHandle </strong>currentProcess = ProcessHandle.current(); System.out.println("PID: " + currentProcess.<strong>pid()</strong>); <strong>ProcessHandle.Info</strong> currentProcessInfo = currentProcess.<strong>info()</strong>; System.out.println("totalCpuDuration: " + currentProcessInfo.<strong>totalCpuDuration()</strong>); System.out.println("user: " + currentProcessInfo.<strong>user()</strong>); } }
<strong>PID: 6004 totalCpuDuration: Optional[PT0.421875S] user: Optional[Tutorialspoint\User]</strong>
The above is the detailed content of What are the improvements to Process API in Java 9?. For more information, please follow other related articles on the PHP Chinese website!