Runtime rt = Runtime.getRuntime();
Process p = rt.exec("notepad.exe");
ProcessHandle ph = p.toHandle();
System.out.println("进程是否运行:" + ph.isAlive());
System.out.println("进程ID:" + ph.pid());
System.out.println("父进程:" + ph.parent());
ProcessHandle.Info info = ph.info();
System.out.println("进程命令:" + info.command());
System.out.println("进程参数:" + info.arguments());
System.out.println("进程启动时间: " + info.startInstant());
System.out.println("进程积计运行时间:" + info.totalCpuDuration());
// 通过CompletetableFuture 在进程结束时运行某个命令
CompletableFuture<ProcessHandle> cf = ph.onExit();
cf.thenRunAsync(() -> System.out.println("程序退出"));
Thread.sleep(5000);
ProcessHandle实例
最新推荐文章于 2022-08-25 04:30:00 发布