The java.lang.Process.destroy() method kills the subprocess. The subprocess represented by this Process object is forcibly terminated.
Following is the declaration for java.lang.Process.destroy() method
public abstract void destroy()
NA
This method does not return a value.
NA
The following example shows the usage of lang.Process.destroy() method.
package com.tutorialspoint; public class ProcessDemo { public static void main(String[] args) { try { // create a new process System.out.println("Creating Process..."); Process p = Runtime.getRuntime().exec("notepad.exe"); // wait 10 seconds System.out.println("Waiting..."); Thread.sleep(10000); // kill the process p.destroy(); System.out.println("Process destroyed."); } catch (Exception ex) { ex.printStackTrace(); } } }
Let us compile and run the above program, this will produce the following result −
Creating Process... Waiting... Process destroyed.