java Process stop entire process tree

点点圈 提交于 2019-12-11 03:16:16

问题


I am using Java Runtime to run commands, including certain CVS commands.
I use:

process = runtime.exec ("cmd /C cvs...");

format for running the Process in Java
I need to have the option of stopping it. For this I use the Java Process destroy method

process.destroy();


However only the cmd is stopped not the cvs process. It continues to run as a separate process without the cmd process as the parent.
There are many references to this on the internet, but I haven't found any satisfactory solution. Thanks


回答1:


This is a problem with the windows cmd shell. Why do you use it? Can't you do exec("cvs ...") instead?




回答2:


It may be possible using Runtime.exec to get the PID of the process you have run. And with that you might be able to shut down the process tree.

You would however need 2 other programs to find the PID and to terminate the process tree.



来源:https://stackoverflow.com/questions/2471657/java-process-stop-entire-process-tree

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