Since Java 9 class Process
has new method long pid()
, so it is as simple as
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "path");
try {
Process p = pb.start();
long pid = p.pid();
} catch (IOException ex) {
// ...
}
More Related Contents:
- How to set working directory with ProcessBuilder
- How do I find the process ID (pid) of a process started in java? [duplicate]
- Runtime.getRuntime().exec(cmd) hanging
- How can a Java program get its own process ID?
- Killing a process using Java
- Difference between ProcessBuilder and Runtime.exec()
- ProcessBuilder: Forwarding stdout and stderr of started processes without blocking the main thread
- Call an executable and pass parameters
- Starting a process in Java?
- Executing another application from Java
- how to compile & run java program in another java program?
- How to Daemonize a Java Program?
- how to change the name of a Java application process?
- How to find and kill running Win-Processes from within Java?
- How to redirect ProcessBuilder’s output to a string?
- Writing to InputStream of a Java Process
- How can I cause a child process to exit when the parent does?
- Java native process timeout
- Launch JVM process from a Java application use Runtime.exec?
- Is there one JVM per Java application?
- CreateProcess error=2, The system cannot find the file specified
- Unable to read InputStream from Java Process (Runtime.getRuntime().exec() or ProcessBuilder)
- Wait for process to finish before proceeding in Java
- Java tool/method to force-kill a child process
- Start CMD by using ProcessBuilder
- Launch Firefox and Wait until it is Closed
- Elevating a ProcessBuilder process via UAC?
- check if some exe program is running on the windows
- Having spaces in Runtime.getRuntime().exec with 2 executables
- Redirect stdin and stdout in Java