问题
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