JDK-6987415 : (process) Process does not have a method to gently terminate
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P4
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2010-09-25
  • Updated: 2014-01-22
  • Resolved: 2014-01-22
Related Reports
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
There are generally 2 ways to end a process:

1) gently asking it to terminate (SIGTERM on *nix, ExitProcess on Windows)
2) forcibly killing it (SIGKILL on *nix, TerminateProcess on Windows)

Currently, Java only supports the 2nd way, with the Process.destroy() method. It would be nice if the 1st way would be supported as well, for example by a Process.stop() method.



JUSTIFICATION :
Asking a process to terminate allows it to do cleanup, close files, leave everything in a consistent state... While it 's good to have a way to forcibly kill a stubborn process, I 'd guess 98% of the time processes will obey to SIGTERM, with the added benefit of proper shutdown.
In particular for Java child processes, this new method would also allow the guaranteed execution of shutdown hooks.

While this is essentialy a duplicate of bug report 4333183, I do believe it is justified to report this again & hope you will reconsider implementing this RFE. The previous bug report is well over 10 years old & has not seen an evaluation comment in over 8 years.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A stop() method in the java.lang.Process class. And possibly also a similar method with an extra "timeout" parameter, something like this:

public void stop(long timeout) {
  p.stop();
  Thread.sleep(timeout); //ignored the InterruptedException for brevity
  try {
    p.exitValue();
  } catch(IllegalThreadStateException e) {
    p.destroy();
  }
}

Comments
destroyForcibly was added in 8 (see JDK-4244896) but SIGTERM has always been the way we kill processes on *nix.
22-01-2014