title: How to Terminate a Process Normally Created using ProcessBuilder
body: <p>I am creating Processes using ProcessBuilder in my Java Application. The created process executes some FFMPEG commands which actually copy the RTSP streams in specified destination media file.</p>
  <pre><code>ProcessBuilder builder = new ProcessBuilder(&quot;ffmpeg&quot;, &quot;-i&quot;, RTSP_URL, &quot;-f&quot;, fileFormat, destFilePath);
  Process processToExecute = builder.start();
  </code></pre>
  <p>I want to close the process before it completes its execution. So, If I run this FFMPEG command directly in windows CMD and then press 'CTRL+C' after 5 seconds then process get terminates with status '2'. And I can play the media file created so far.</p>
  <p>So, If I do the same operation in my Java Application using:</p>
  <pre><code> process.destroy(); //I call this method after 5 sec
  </code></pre>
  <p>I get the status code '1' which means abnormal termination. I get the status by the following way:</p>
  <pre><code> processToExecute.destroy();
   processToExecute.exitValue(); //This return me status '1'
  </code></pre>
  <p>And I can't play the media file and I think this is due to the abnormal termination of the process.</p>
  <p>So how I can terminate the process created using ProcessBuilder in the same way we do in CMD with (CTRL+C) so that I may play the created media file ?</p>
  <p>I want to terminate process (created using ProcessBuilder) in Java Application with status code of '2' that I get when I terminate process using CMD.</p>
  <h1>EDIT#01: --- Sharing Findings</h1>
  <p>So, when I try to delete that file once app terminates, I get the following error:</p>
  <pre><code>The Action Can't be Performed Because File is Opened in FFMPEG.exe
  </code></pre>
  <p>Which means that process is not terminating the command it is executing. That command still has occupied this file that's why I am not getting able to play it. Process gets terminate when I call:</p>
  <pre><code> processToExecute.destroy();
  </code></pre>
  <p>But, the task it is performing (that is execution of a command) is still active. Strange!!!!</p>
  <h1>EDIT#02: Sharing Ultimate Reason</h1>
  <p>Actually If I directly press 'CTRL+C' or 'q' in cmd when process is running then it terminates the process successfully and this process is no more visible in the currently executing processes lists.</p>
  <p>And Programatically when I call method:</p>
  <pre><code>cmd&gt; processToExecute.destroy();
  </code></pre>
  <p>It terminates the process but when I see the list of currently executing processes I can still see them over there.</p>
  <p>And same scenario exists If I try to terminate this process using 'taskkill' or 'kill' command in another CMD by specifying their's name or pid that still process terminates abnormally.</p>
  <p>P.S. I use the following command to see the running processes:</p>
  <pre><code>tasklist
  </code></pre>
  <p>So from this it proves that destroy() method from Application and 'taskkill or kill' command from another CMD is not terminating the process normally that pressing 'CTRL+C' and 'q' does.</p>