Getting information about a process

To get information about a process, we need access to the Info object of the process. This is available through a ProcessHandle. We use a call to the handle.info() method to return it.

The Info interface defines query methods that deliver information about the process. These are:

  • command() returns an Optional<String> containing the command that was used to start the process
  • arguments() returns an Optional<String[]> that contains the arguments that were used on the command-line after the command to start the process
  • commandLine() returns an Optional<String> that contains the whole command-line
  • startInstant() returns an Optional<Instant>, which essentially represents the time the process was started
  • totalCpuDuration() ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.