如何获取使用ProcessBuilder启动的shell脚本的进程ID?
String cmd[] = { "sh", "-c", "ls -l" };
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectOutput(new File(request.getParameter("output_file_name")));
Process p = pb.start();
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
p.destroy();
答案 0 :(得分:-1)
请参阅:How can a Java program get its own process ID?
Java 9现在支持这一点。否则,从您的应用程序中调出脚本以保存您将在某处读取的PID