public static boolean isAlive ( String pid ) { ShellCommandExecutor shexec = null ; try { String [ ] args = { "kill" , "-0" , pid } ; shexec = new ShellCommandExecutor ( args ) ; shexec . execute ( ) ; } catch ( ExitCodeException ee ) { return false ; } catch ( IOException ioe ) { LOG . warn ( "Error executing shell command " + Arrays . toString ( shexec . getExecString ( ) ) + ioe ) ; return false ; } return ( shexec . getExitCode ( ) == 0 ? true : false ) ; }
Is the process with PID pid still alive? This method assumes that isAlive is called on a pid that was alive not too long ago and hence assumes no chance of pid - wrapping - around .