Share this page 

Kill a process with a PID Tag(s): Environment


With JDK9
public class KillProcess {
   public static void main(String[] args) {
      //                PID
      ProcessHandle.of(16728).ifPresent(ProcessHandle::destroy); // or ProcessHandle::destroyForcibly
   }
}
With previous JDK version, a plateform dependant solution was required.
For example, on a Windows Professionnal installation, you launch the taskkill utility :
Runtime.getRuntime().exec("taskkill /F /PID 827");
To retrieve a PID for a given program, see Get a PID.
To retrieve the PID for the current Java process, see Get the current PID.