Process API Updates
Java 9 has come with the changes which will let you fetch the pid of a process. Following code shows how to get a pid with Java 9
ProcessBuilder pb = new ProcessBuilder("notepad"); Process p = pb.start(); System.out.println("Pid of Process : " + p.getPid());
getPid function internally call getProcessId0 with process’s handle to retrieve pid. getProcessId0 is a native method.
Apart from process id, other targeted changes are :
- Ability to get/set the process name
- Ability to enumerate Java virtual machines and processes to get pid, name, state, and perhaps resource usage
- Api to do “End Process Tree”.
Thanks Robin for the update, JDK 9 docs are now available here http://download.java.net/jdk9/docs/api/java/lang/ProcessBuilder.html
Pingback: Java 9 Features | Java and Me
Looks like is in the docs now…
http://download.java.net/jdk9/docs/api/java/lang/ProcessBuilder.html