The right way to kill a process in Java -


what's best way kill process in java ?

get pid , killing runtime.exec() ?

use destroyforcibly() ?

what's difference between these 2 methods, , there others solutions ?

if process want kill has been started application

then have reference (processbuilder.start() or runtime.exec() both return reference). in case, can call p.destroy(). think cleanest way (but careful: sub-processes started p may stay alive, check http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4770092 more info).

the destroyforcibly should used if destroy() failed after timeout. in nutshell

  1. terminate process destroy()
  2. allow process exit gracefully reasonable timeout
  3. kill destroyforcibly() if process still alive

if process want kill external

then don't have choice: need pass through os api (runtime.exec). on windows, program call taskkill.exe, while on mac , linux can try kill.


have @ https://github.com/zeroturnaround/zt-exec/issues/19 , killing process using java , http://invisiblecomputer.wonderhowto.com/how-to/code-simple-java-app-kill-any-process-after-specified-time-0133513/ more info.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -