Java 9 : Process API updates

Java's Process API has been quite primitive, with support only to launch new
processes, redirect the processes' output, and error streams. In this release, the
updates to the Process API enable the following:

Get the PID of the current JVM process and any other processes spawned by the
JVM
Enumerate the processes running in the system to get information such as PID,
name, and resource usage
Managing process trees
Managing sub processes

Let's look at a sample code, which prints the current PID as well as the current
process information:

//NewFeatures.java
public class NewFeatures{
public static void main(String [] args) {
ProcessHandle currentProcess = ProcessHandle.current();
System.out.println("PID: " + currentProcess.getPid());
ProcessHandle.Info currentProcessInfo = currentProcess.info();
System.out.println("Info: " + currentProcessInfo);
}
}


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation