public static void terminateProcessGroup ( String pgrpId ) { ShellCommandExecutor shexec = null ; try { String [ ] args = { "kill" , "--" , "-" + pgrpId } ; shexec = new ShellCommandExecutor ( args ) ; shexec . execute ( ) ; } catch ( IOException ioe ) { LOG . warn ( "Error executing shell command " + ioe ) ; } finally { LOG . info ( "Killing all processes in the process group " + pgrpId + " with SIGTERM. Exit code " + shexec . getExitCode ( ) ) ; } }
Sends terminate signal to all the process belonging to the passed process group allowing the group to gracefully exit .