Home  >  Article  >  Java  >  What new methods are added to the Process API in Java 9?

What new methods are added to the Process API in Java 9?

WBOY
WBOYforward
2023-09-09 10:49:02719browse

在Java 9中,Process API新增了哪些新的方法?

Java 9 improves the Process class by adding new methods and also provides new interfaces: ProcessHandle and ProcessHandle .Info to get all the details about the process and its information.

The following is a list of new methods added to Process in Java 9

  • booleansupportsNormalTermination ():Returns true if executing destroy() terminates the process normally, Otherwise return false.
  • long pid():Can return the native process ID of the process.
  • ProcessHandle toHandle(): It can return the ProcessHandle of the process.
  • Streamchildren(): It can return a snapshot of the direct children of a process.
  • Streamdescendants(): It can return a snapshot of the descendants of a process.
  • ProcessHandle.Info info(): It can return a snapshot of information about the process.
  • CompletableFuture onExit(): It can return a CompletableFuture to terminate the process.

Example

public class ProcessTest {
   public static void main(String args[]) {
<strong>      ProcessHandle </strong>processHandle = ProcessHandle.current();
<strong>      ProcessHandle.Info</strong> processInfo = processHandle.info();
      System.out.println(processHandle.<strong>pid()</strong>);
      System.out.println(processHandle.<strong>parent()</strong>);
      System.out.println(processInfo.<strong>arguments()</strong>.<strong>isPresent()</strong>);
      System.out.println(processInfo.<strong>command()</strong>.<strong>isPresent()</strong>);
      System.out.println(processInfo.<strong>command().get().contains</strong>("tutorialspoint"));
      System.out.println(processInfo.<strong>startInstant().isPresent()</strong>);
   }
}

Output

<strong>4892
Optional[7788]
false
true
false
true</strong>

The above is the detailed content of What new methods are added to the Process API in Java 9?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete