Java如何使用代码获取pid
jdk8及以下版本
final String name = ManagementFactory.getRuntimeMXBean().getName();
System.out.println(name);
//输出:36368@DESKTOP-CBD4516 36368就是pid
jdk9
long pid = ProcessHandle.current().pid();
System.out.println(pid);
//输出:36368 36368就是pid
Loading...