Java 9 provides a refined Process API to control and manage the process with better performance in your operating system.
Process control could be made easier by accessing the process ID (PID), username, and resource utilization with the processing path information from the operating system. The multithreaded approach from previous versions is refined to easily deal with process trees and destruct or manage processes that have multiple subprocesses.
The following is an example of retrieving the PID of the current process with this API:
private static int getOwnProcessID(){ return ProcessHandle.current().getPid(); }
The following is a code snippet for getting a list of all the processes running on the operating system:
private static void listProcesses(){ ProcessHandle.allProcesses().forEach((h) -> printHandle(h)); } private static void printHandle(ProcessHandle procHandle) { // get info from handle ProcessHandle.Info procInfo = procHandle...