public static void kill ( final long pid ) throws IOException , InterruptedException { if ( isUnix ( ) ) { final Process process = new ProcessBuilder ( ) . command ( "bash" , "-c" , "kill" , "-9" , String . valueOf ( pid ) ) . start ( ) ; final int returnCode = process . waitFor ( ) ; LOG . fine ( "Kill returned: " + returnCode ) ; } else if ( isWindows ( ) ) { final Process process = new ProcessBuilder ( ) . command ( "taskkill.exe" , "/f" , "/pid" , String . valueOf ( pid ) ) . start ( ) ; final int returnCode = process . waitFor ( ) ; LOG . fine ( "Kill returned: " + returnCode ) ; } else { throw new UnsupportedOperationException ( "Unable to execute kill on unknown OS" ) ; } }
Kill the process .