Java Process.destroy()

Syntax

Process.destroy() has the following syntax.

public abstract void destroy()

Example

In the following code shows how to use Process.destroy() method.


public class Main {
/*from w  w  w  . j  a va  2  s. c  om*/
   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();
      }

   }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable