I am trying to run the automation scripts using java-Selenium TestNG. For opening browser I have invoked chrome driver. even after stopping the scripts the chrome driver is running in Background process in task manager. For ex If I execute my script for 20 time then the chrome driver is running for 20 time in the task manager. I didnt face any issue because of this problem. but still wanted to know should I add anything in my script to stop those drivers? . Will it cause any issue in the future ?
- 
                    Possible duplicate of [Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?](https://stackoverflow.com/questions/47999568/selenium-how-to-stop-geckodriver-process-impacting-pc-memory-without-calling) – undetected Selenium Feb 09 '18 at 02:11
5 Answers
You can kill unclosed process writing in @AfterSuite (in Java)
If You launch test on Windows:
//kill chromedriver
Runtime.getRuntime().exec("taskkill /im chromedriver.exe /f");
If You launch test on Linux:
String[] cmd = new String[]{"/bin/sh", "killchrome.sh"};
Process pr = Runtime.getRuntime().exec(cmd);
and in killchrome.sh (in this example file is in main project directory) you should write
kill $(ps aux | grep 'chromedrive[r]' | awk '{print $2}')
 
    
    - 670
- 9
- 15
WebDriver driver = new ChromeDriver();
try{
  ==========      ==========
    YOUR CODE GOES HERE
  ==========      ==========
} catch (Exception e) {
  ==========      ==========
    YOUR CODE GOES HERE
  ==========      ==========
} finally{
  driver.quit();
}
It is always a good practice to close your instance in your finally block.
 
    
    - 69
- 4
Kill Multiple Processes From the Command Line The first thing you’ll need to do is open up a command prompt, and then use the taskkill command with the following syntax:
taskkill /F /IM <processname.exe> /T
These parameters will forcibly kill any process matching the name of the executable that you specify. For instance, to kill all iexplore.exe processes, we’d use:
[![taskkill /F /IM iexplore.exe][1]][1]
 
    
    - 614
- 1
- 6
- 12
Use:
driver.quit();
This will kill shut down the driver and kill the instance.
 
    
    - 1,899
- 1
- 13
- 23
This script taskkill /FI "IMAGENAME eq geckodriver.exe" /F could kill geckodriver for you. If you want to kill chromedriver, just replace the name with newer name
 
    
    - 579
- 4
- 6
 
    