How to get PID of process I've just started within java program?
问题 I\'ve started a process with following code ProcessBuilder pb = new ProcessBuilder(\"cmd\", \"/c\", \"path\"); try { Process p = pb.start(); } catch (IOException ex) {} Now I need to know the process\'s pid that I\'ve just started. 回答1: There is no public API for this yet. see Sun Bug 4244896, Sun Bug 4250622 As a workaround: Runtime.exec(...) returns an Object of type java.lang.Process The Process class is abstract, and what you get back is some subclass of Process which is designed for your