I'm using Selenium in Java to automate Google Chrome. When my program exits, a chromedriver.exe instance is left in memory. I know that I can use driver.quit() in e.g. a finally block to shut down the current instance. However, if the Java application is killed at any time (like during debug sessions), this cleanup is of course never performed.
I'm looking for a solution to make the chromedriver.exe a child process of the Java process so when the Java process exits, the child process also dies automatically. Solutions like Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe"); kill all chromedriver.exe instances but this may mess up other Selenium processes on the system which is not ideal. Also this would not work against forcibly killing the process either.