I have a process (on Windows is named chromedriver.exe) which is created when I create a new instance of Selenium Chrome Driver.
So I'm not starting the process myself, and yet I would like a java.lang.Process instance representing that process, if that's possible.
The reason why I want to create such instance is that I want to call Process.waitFor() to wait until the process is actually terminated after I issued (if on Windows) a Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe").
I cannot introduce a new dependency on third-party libraries for this specific need only. I could just use anything from Apache Commons.
So the question is: is there a way from my code to get a Process instance representing a running process that was not started from my code ?
The reason why I want to be able to kill that process is that an abrupt termination like a JVM crash might not let WebDriver.quit() terminate the process. So before creating the ChromeDriver instance that causes the process to start I want to kill any possibly already existing such processes.
The reason why I'm using exec("taskkill...") to kill the process on Windows (I'd use killall on Linux) is that that's the only way I found so far, but if it is possible to get a Process instance that represent that process I'd also try using Process.destroy() to see if the "subprocess" mentioned in its description "Kills the subprocess" is referring to that process.