Kill the process tree in windows using Java

I have a Java webstart process that is part of a windows script package. In this case, I use the javaws command in the script package. This script (start.bat) match is called programmatically using the "apache commons exec". In some cases, the java process called by javaws freezes, and I have to kill the whole process thread, starting with the script start.bat package. Is there a programmatic way to kill the entire process tree via apache commons exec?

I tried using "execWatchdog.destroyProcess ();" to the "start.bat" script. However, it only kills the start.bat process, not the entire process tree.

Is there a way to kill the entire process tree via apache-commons-exec or similar code?

I saw this question Running the equivalent of “Kill Process Tree” in C ++ in windows , which performs an equivalent task in C ++. I am wondering if any of the built-in Windows system calls have implemented through JNI.

+5
source share
3 answers

Finally, it turned out to be something workable, even though it is a circular path.

The Apache Commons Exec API contains the CommandLauncher class, which returns a java.lang.Process object. Thanks link

Here's a link to get the windows process id from java.lang.Process. It uses JNA libraries.

, , , //String killCmd = "taskkill/F/T/PID" + JNAHandler.getPid();

+8

, , Java- . JNI, , Java.

, Java: http://bugs.sun.com/view_bug.do?bug_id=4770092

, Java , Java 8.

+2

As far as I know, this is not in commons-exec. It is not even possible to get the PID of any process that you just started. You could trapkill the signal in your bash script, and the handler will kill the subprocess (s) when the script process is killed.

+1
source

All Articles