Modern Process API
Inspect and manage OS processes with ProcessHandle.
Porównanie kodu
✕ Java 8
Process p = Runtime.getRuntime()
.exec("ls -la");
int code = p.waitFor();
// no way to get PID
// no easy process info
✓ Java 9+
ProcessHandle ph =
ProcessHandle.current();
long pid = ph.pid();
ph.info().command()
.ifPresent(IO::println);
ph.children().forEach(
c -> IO.println(c.pid()));
Widzisz problem z tym kodem? Daj nam znać.
Dlaczego nowoczesne podejście wygrywa
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.
Stare podejście
Runtime.exec()
Nowoczesne podejście
ProcessHandle
Od JDK
9
Poziom trudności
Średniozaawansowany
Wsparcie JDK
Modern Process API
Dostępne
Widely available since JDK 9 (Sept 2017)
Jak to działa
ProcessHandle provides PIDs, process info (command, arguments, start time, CPU usage), parent/child relationships, and process destruction. No more undocumented Process internals.
Powiązana dokumentacja