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
- terminate process
destroy() - allow process exit gracefully reasonable timeout
- 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
Post a Comment