โ— Shell
clean mode source โ†—

Modern Process API

Code Comparison

Process p = Runtime.getRuntime()
    .exec("ls -la");
int code = p.waitFor();
// no way to get PID
// no easy process info
ProcessHandle ph =
    ProcessHandle.current();
long pid = ph.pid();
ph.info().command()
    .ifPresent(IO::println);
ph.children().forEach(
    c -> IO.println(c.pid()));

Why the modern way wins

๐Ÿ”

Full info

Access PID, command, arguments, start time, CPU usage.

๐ŸŒณ

Process tree

Navigate parent, children, and descendants.

๐Ÿ“Š

Monitoring

onExit() returns a CompletableFuture for async monitoring.

Old Approach

Runtime.exec()

Modern Approach

ProcessHandle

JDK Support

Modern Process API

Available

Widely available since JDK 9 (Sept 2017)

How it works

ProcessHandle provides PIDs, process info (command, arguments, start time, CPU usage), parent/child relationships, and process destruction. No more undocumented Process internals.

Related Documentation

Proof