Note that there are some explanatory texts on larger screens.

plurals
  1. POJava tool/method to force-kill a child process
    primarykey
    data
    text
    <p>I am looking for a Java tool/package/library that will allow me to force-kill a child process.</p> <p>This tool/package/library must work on Windows platform (mandatory). Support for Linux/Unix is desired.</p> <h2>My Problem</h2> <p>My Java code creates a child process that will simply not react to the standard Java way for killing a child process: process.destroy(), and, since I do not have the child's source code, I cannot program it to better handle termination requests.</p> <p>I have tried closing the child process' error input and output stream before calling destroy(), and for no effect.</p> <p>I have even tried passing ctrlBreak signal (char=3) directly into child.getOutputStream(), and again have received the same results.</p> <p>The workaround I have finally managed to find was to:</p> <ol> <li><p>Obtain the child's PID upon its creation This can be done in Windows by diffing the process lists before and after the child's creation (<code>getRuntime().exec("tasklist /v")</code>)</p></li> <li><p>Use the child's PID to issue a force kill system command<br> in Windows: <code>getRuntime().exec("taskkill /pid " + childPid + " /f")</code></p></li> </ol> <p>But - this is complex code I have no desire to debug and maintain, plus the problem itself, I have no doubt, was previously encountered by many other java developers, which leads me to the hope that such a Java tool/package/library already exists.</p> <p>I just don't know its name...</p> <p>PS: My child process was created by <code>Runtime.getRuntime().exec(cmd)</code>, but I get the same behaviour using a ProcessBuilder.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload