O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JEP 102 -- 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()); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required