/** * Gets a value indicating if a subprocess of ctags was started and it is * not alive. * @return {@code true} if the instance should be considered closed and no * longer usable. */ public boolean isClosed() { return ctags != null && !ctags.isAlive(); }
public boolean isAlive() { return process.isAlive(); }
public boolean isAlive() { return !killed && process.isAlive(); } }
@Override public void close() throws IOException { if (process.isAlive()) { process.destroy(); try { process.waitFor(10, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }
@Nullable @Override public RunnerTaskState getRunnerTaskState(String taskId) { final ForkingTaskRunnerWorkItem workItem = tasks.get(taskId); if (workItem == null) { return null; } else { if (workItem.processHolder == null) { return RunnerTaskState.PENDING; } else if (workItem.processHolder.process.isAlive()) { return RunnerTaskState.RUNNING; } else { return RunnerTaskState.NONE; } } }
/** * Returns true if a process identified by the specified Process is currently running on this host * machine. * * @param process the Process to check * @return true if the Process is a currently running process */ public static boolean isProcessAlive(final Process process) { notNull(process, "Invalid process '" + process + "' specified"); return process.isAlive(); }
protected void assertThatProcessIsAlive(final Process process) { assertThat(process.isAlive()).isTrue(); }
/** * this only kills the process of "gfsh -e command", it does not kill the child processes started * by this command. */ public void killProcess() { process.destroyForcibly(); if (process.isAlive()) { // process may not terminate immediately after destroyForcibly boolean exited = false; try { exited = process.waitFor(1, TimeUnit.MINUTES); } catch (InterruptedException e) { throw new RuntimeException(e.getMessage(), e); } if (!exited) { throw new RuntimeException("failed to destroy the process of " + workingDir.getName()); } } }
protected void assertThatProcessAndReadersDied() throws InterruptedException { assertThat(process.isAlive()).isFalse(); assertThat(stdout.join(READER_JOIN_TIMEOUT_MILLIS).isRunning()).isFalse(); assertThat(stderr.join(READER_JOIN_TIMEOUT_MILLIS).isRunning()).isFalse(); }
Dispatcher get( @SuppressWarnings( "hiding" ) Process process ) { while ( dispatcher == null && process.isAlive() ) { try { Thread.sleep( 10 ); } catch ( InterruptedException e ) { Thread.currentThread().interrupt(); } } return dispatcher; }
/** A straightforward constructor. */ private RunningProcess(Process process) { this.process = process; Writer errWriter = new BufferedWriter(new OutputStreamWriter(System.err)); this.stderr = new StreamGobbler(process.getErrorStream(), errWriter); this.stderr.start(); Writer outWriter = new BufferedWriter(new OutputStreamWriter(System.out)); this.stdout = new StreamGobbler(process.getErrorStream(), outWriter); this.stdout.start(); this.shutdownHoook = new Thread(() -> { log.info("Killing process " + WebServiceAnnotator.this); this.stdout.kill(); this.stderr.kill(); if (this.process.isAlive()) { this.process.destroy(); } this.ready = false; }); Runtime.getRuntime().addShutdownHook(this.shutdownHoook); }
public PythonEntryPoint getPythonEntryPoint() throws NoSuchKernelException { if (pythonProcess == null || !pythonProcess.isAlive() || clientServer == null) { initPythonProcess(); } if (pep == null) { this.pep = initPythonEntryPoint(); } return pep; }
private void initPythonProcess() throws NoSuchKernelException { //cleanup communication resources if already in use exit(); port = findFreePort(); pythonPort = findFreePort(); try { ProcessBuilder pb = new ProcessBuilder(getPy4jCommand()); pb.redirectError(ProcessBuilder.Redirect.INHERIT); pythonProcess = pb.start(); BufferedReader br = new BufferedReader(new InputStreamReader(pythonProcess.getInputStream())); while (!PY4J_INIT_MESSAGE.equals(br.readLine()) && pythonProcess.isAlive()) { //wait for python process to initialize properly } if (!pythonProcess.isAlive() && pythonProcess.exitValue() == NO_SUCH_KERNEL_CODE) { throw new NoSuchKernelException(kernelName); } } catch (IOException e) { e.printStackTrace(); } }
@Signature public boolean isAlive() { return getProcess().isAlive(); }
protected void givenRunningProcessWithStreamReaders(final Class<?> mainClass) { givenStartedProcess(mainClass); assertThat(process.isAlive()).isTrue(); await().untilAsserted(() -> assertThat(stdout.isRunning()).isTrue()); await().untilAsserted(() -> assertThat(stderr.isRunning()).isTrue()); }
@OnUnscheduled public void shutdownExecutor() { try { executor.shutdown(); } finally { if (this.externalProcess.isAlive()) { this.getLogger().info("Process hasn't terminated, forcing the interrupt"); this.externalProcess.destroyForcibly(); } } }
/** * Joins with the consumer Threads. Calls {@link Thread#join()} on the two * consumers. */ public void done() { if ( process.isAlive() ) { process.destroyForcibly(); } try { out.join(); } catch ( InterruptedException e ) { Thread.interrupted(); e.printStackTrace(); } try { err.join(); } catch ( InterruptedException e ) { Thread.interrupted(); e.printStackTrace(); } }
@Override public Integer retriableCall() throws Exception { while (true) { sleeper.sleep(config.getPostRestoreHookHeartbeatCheckFrequencyInMs()); if (System.currentTimeMillis() - heartBeatFile.lastModified() > config.getPostRestoreHookHeartBeatTimeoutInMs()) { // kick off post restore hook process, since there is no heartbeat logger.info( "No heartbeat for the last {} ms, killing the existing process.", config.getPostRestoreHookHeartBeatTimeoutInMs()); if (process.isAlive()) { process.destroyForcibly(); } return 0; } } } });
private void killEthereumJ() { try { if (!proc.isAlive()) { testLogger.warn("Not killing EthereumJ, already finished."); return; } testLogger.info("Killing EthereumJ"); // Gradle (PID) -> Java app (another PID) if (killUnixProcess(getChildPID(getUnixPID(proc))) != 0) { throw new RuntimeException("Killing EthereunJ was not successful"); } } catch (Exception ex) { testLogger.error("Error during shutting down of main EthereumJ", ex); fatalErrors.addAndGet(1); } }
@Test public void ProcessMonitorImpl_is_a_proxy_of_Process() throws Exception { Process process = mock(Process.class, RETURNS_DEEP_STUBS); ProcessCommands commands = mock(ProcessCommands.class, RETURNS_DEEP_STUBS); ProcessCommandsProcessMonitor underTest = new ProcessCommandsProcessMonitor(process, ProcessId.WEB_SERVER, commands); underTest.waitFor(); verify(process).waitFor(); underTest.closeStreams(); verify(process.getErrorStream()).close(); verify(process.getInputStream()).close(); verify(process.getOutputStream()).close(); underTest.destroyForcibly(); verify(process).destroyForcibly(); assertThat(underTest.getInputStream()).isNotNull(); underTest.isAlive(); verify(process).isAlive(); underTest.waitFor(123, TimeUnit.MILLISECONDS); verify(process).waitFor(123, TimeUnit.MILLISECONDS); }