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

How to do it...

  1. Create a simple class and use ProcessHandle.current() to get ProcessHandle for the current Java process:
        ProcessHandle handle = ProcessHandle.current();
  1. We have added some code, which will add some running time to the code:
        for ( int i = 0 ; i < 100; i++){
          Thread.sleep(1000);
        }
  1. Use the info() method on the instance of ProcessHandle to get an instance of ProcessHandle.Info:
        ProcessHandle.Info info = handle.info();
  1. Use the instance of ProcessHandle.Info to get all the information made available by the interface:
 System.out.println("Command line: " + info.commandLine().get()); System.out.println("Command: " + info.command().get()); System.out.println("Arguments: " + String.join(" ", info.arguments().get())); System.out.println("User: ...

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