title: Java tool/method to force-kill a child process
body: <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>