How do I kill a runaway Java process started by Ant?

一个人想着一个人 提交于 2019-12-06 05:07:48

Unfortunately, it appears that this is a long-standing and known issue.

When the Ant task is terminated, the forked Java process shutdown hooks are not fired. (This seems to have been an issue since Java 1.4 (!))

For reference:

If you set fork to "no", the same VM will be used, so killing the ant process will kill this specific java process too.

Chad Nouis

A cross-platform solution for killing processes will involve a bit of effort. See Java tool/method to force-kill a child process.

For Windows XP and later, the following batch script may be helpful:

for /f "skip=1 usebackq" %%h in (`wmic process where "Name like 'java%%.exe' and CommandLine like '%%path.to.MyClass%%'" get ProcessId ^| findstr .`) do taskkill /F /T /PID %%h

This script uses the built-in WMIC command to find the Process ID of any running java*.exe process that has path.to.MyClass somewhere in the Command Line. If you need WMIC to be more specific in matching your particular Java process, play with the properties listed by WMIC's help mode:

wmic process get /?

taskkill will kill a process tree (/T) given the root Process ID (/PID).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!