Skip to content

Instantly share code, notes, and snippets.

@ahndmal
Created April 4, 2026 17:37
Show Gist options
  • Select an option

  • Save ahndmal/f1325aff7adbdf70174e63dbd77ca76e to your computer and use it in GitHub Desktop.

Select an option

Save ahndmal/f1325aff7adbdf70174e63dbd77ca76e to your computer and use it in GitHub Desktop.
public static void getInfoTest() throws IOException {
ProcessBuilder pb = new ProcessBuilder("echo", "Hello World!");
String na = "<not available>";
Process p = pb.start();
ProcessHandle.Info info = p.info();
System.out.printf("Process ID: %s%n", p.pid());
System.out.printf("Command name: %s%n", info.command().orElse(na));
System.out.printf("Command line: %s%n", info.commandLine().orElse(na));
System.out.printf("Start time: %s%n",
info.startInstant().map((Instant i) -> i
.atZone(ZoneId.systemDefault()).toLocalDateTime().toString())
.orElse(na));
System.out.printf("Arguments: %s%n",
info.arguments().map(
(String[] a) -> Stream.of(a).collect(Collectors.joining(" ")))
.orElse(na));
System.out.printf("User: %s%n", info.user().orElse(na));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment