@Override public boolean isAlive() throws IOException, InterruptedException { try { proc.exitValue(); return false; } catch (IllegalThreadStateException e) { return true; } }
private ProcessState checkPythonProcessHealth() { try { int value = process.exitValue(); if (value != 0) { return ProcessState.FAILED; } else { return ProcessState.STOPPED; } } catch (IllegalThreadStateException ignored) {//Process still running return ProcessState.RUNNING; } }
private Integer tryGetExitValue( final Process process ) { try { return process.exitValue(); } catch ( IllegalThreadStateException e ) { // Thrown if this process hasn't exited yet. return null; } }
/** * @return exit code of the process if process is terminated, -1 if process is not started or terminated. */ public int getExitCode() { try { return this._subprocess != null ? this._subprocess.exitValue() : -1; } catch (IllegalThreadStateException e) { return -1; } }
public boolean isRunning() { try { process.exitValue(); } catch (IllegalThreadStateException e) { return true; } return false; }
public static boolean isAlive(Process process) { try { if (process != null) process.exitValue(); return false; } catch (IllegalThreadStateException e) { return true; } }
/** * * @return exit code of the process if process is terminated, -1 if process is not started or terminated. */ public int getExitCode() { try { return this._subprocess != null ? this._subprocess.exitValue() : -1; } catch (IllegalThreadStateException e) { return -1; } }
private static final boolean procDone( Process p ) { try { p.exitValue(); return true; } catch ( IllegalThreadStateException e ) { return false; } }
public void close() { try { process.exitValue(); } catch (NullPointerException ignored) { //exception occurred before process was started } catch (IllegalThreadStateException ignored) { //process still active process.destroy(); } finally { try { if (server != null) { server.close(); } } catch (IOException e) { LOG.error("Failed to close socket.", e); } } }
@Override public void run() { Process p = shell.process(); try { p.exitValue(); } catch (Exception e) { //Process has not terminated. //So check if it has completed //if not just destroy it. if (p != null && !shell.completed.get()) { p.destroy(); } } } }
private void generateHFile (FileDescriptor file) throws Exception { String className = getFullyQualifiedClassName(file); String command = "javah -classpath " + classpath + " -o " + jniDir.path() + "/" + className + ".h " + className; Process process = Runtime.getRuntime().exec(command); process.waitFor(); if (process.exitValue() != 0) { System.out.println(); System.out.println("Command: " + command); InputStream errorStream = process.getErrorStream(); int c = 0; while ((c = errorStream.read()) != -1) { System.out.print((char)c); } } }
private void generateHFile (FileDescriptor file) throws Exception { String className = getFullyQualifiedClassName(file); String command = "javah -classpath " + classpath + " -o " + jniDir.path() + "/" + className + ".h " + className; Process process = Runtime.getRuntime().exec(command); process.waitFor(); if (process.exitValue() != 0) { System.out.println(); System.out.println("Command: " + command); InputStream errorStream = process.getErrorStream(); int c = 0; while ((c = errorStream.read()) != -1) { System.out.print((char)c); } } }
private static boolean startProcess (String[] commands, File directory, final CharCallback callback) { try { final Process process = new ProcessBuilder(commands).redirectErrorStream(true).directory(directory).start(); Thread t = new Thread(new Runnable() { @Override public void run () { BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1); try { int c = 0; while ((c = reader.read()) != -1) { callback.character((char)c); } } catch (IOException e) { // e.printStackTrace(); } } }); t.setDaemon(true); t.start(); process.waitFor(); t.interrupt(); return process.exitValue() == 0; } catch (Exception e) { e.printStackTrace(); return false; } } }
@Override public void run() { Process p = shell.getProcess(); try { p.exitValue(); } catch (Exception e) { //Process has not terminated. //So check if it has completed //if not just destroy it. if (p != null && !shell.completed.get()) { shell.setTimedOut(); p.destroy(); } } } }
@Override public void run() { Process p = shell.getProcess(); try { p.exitValue(); } catch (Exception e) { //Process has not terminated. //So check if it has completed //if not just destroy it. if (p != null && !shell.completed.get()) { shell.setTimedOut(); p.destroy(); } } } }
public boolean checkSqlProcessRunning( Process sqlProcess ) { try { int exitValue = sqlProcess.exitValue(); logError( "SQL process exit code: " + exitValue ); return false; } catch ( IllegalThreadStateException e ) { // ignore this exception since it is thrown when exitValue() is called on a // running process // Do nothing SQL Process still running return true; } }
public boolean isAlive() { try { _process.exitValue(); return false; } catch( IllegalThreadStateException xe ) { return true; } catch( Exception e ) { throw Log.errRTExcept(e); } }
public static int processLauncherAndWait(Map<String, Object> conf, String user, List<String> args, final Map<String, String> environment, final String logPreFix) throws IOException { int ret = 0; Process process = processLauncher(conf, user, null, args, environment, logPreFix, null, null); if (StringUtils.isNotBlank(logPreFix)) { Utils.readAndLogStream(logPreFix, process.getInputStream()); } try { process.waitFor(); } catch (InterruptedException e) { LOG.info("{} interrupted.", logPreFix); } ret = process.exitValue(); return ret; }
@Test public void shouldReturnFalseWhenAProcessHasExited(){ Process process = getMockedProcess(mock(OutputStream.class)); when(process.exitValue()).thenReturn(1); ProcessWrapper processWrapper = new ProcessWrapper(process, "", "", inMemoryConsumer(), "utf-8", null); assertThat(processWrapper.isRunning(), is(false)); }
@Test public void shouldReturnTrueWhenAProcessIsRunning(){ Process process = getMockedProcess(mock(OutputStream.class)); when(process.exitValue()).thenThrow(new IllegalThreadStateException()); ProcessWrapper processWrapper = new ProcessWrapper(process, "", "", inMemoryConsumer(), "utf-8", null); assertThat(processWrapper.isRunning(), is(true)); }