public static void terminateProcess ( String pid ) { ShellCommandExecutor shexec = null ; String errMsg = null ; try { String [ ] args = { "kill" , pid } ; shexec = new ShellCommandExecutor ( args ) ; shexec . execute ( ) ; } catch ( IOException ioe ) { // Do nothing, we log the exit code in the finally block. errMsg = ioe . getMessage ( ) ; } finally { LOG . info ( "Killing process " + pid + " with SIGTERM. Exit code " + shexec . getExitCode ( ) + ( errMsg == null ? "" : " (" + errMsg + ")" ) ) ; } }
Sends terminate signal to the process allowing it to gracefully exit .