Killing a process using Java

Jeel Shah picture Jeel Shah · Jun 15, 2011 · Viewed 170.8k times · Source

I would like to know how to "kill" a process that has started up. I am aware of the Process API, but I am not sure, If I can use that to "kill" an already running process, such as firefox.exe etc. If the Process API can be used, can you please point me into the correct direction? If not, what are the other available options? Thanks.

Answer

Laksitha Ranasingha picture Laksitha Ranasingha · Jul 6, 2012

On Windows, you could use this command.

taskkill /F /IM <processname>.exe 

To kill it forcefully, you may use;

Runtime.getRuntime().exec("taskkill /F /IM <processname>.exe")