protected static Integer identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException handled) { return null; } }
/** * Returns specified pid if it's unused. Else returns randomly unused pid between * {@code lowerBound} (inclusive) and {@code upperBound} (inclusive). */ public int findAvailablePid(final int pid) throws TimeoutException { if (isProcessAlive(pid)) { return pid; } return findAvailablePid(); }
private int readOtherPid() { int otherPid = 0; try { otherPid = ProcessUtils.readPid(pidFile); } catch (NumberFormatException | IOException ignore) { // suppress } return otherPid; }
private static Integer identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException ignore) { return null; } }
public boolean isVmWithProcessIdRunning() { // note: this will use JNA if available or return false return ProcessUtils.isProcessAlive(this.getPid()); }
int identifyPid() throws PidUnavailableException { return ProcessUtils.identifyPid(); }
private boolean isProcessAlive(final int pid) { return ignoreIsPidAlive() || ProcessUtils.isProcessAlive(pid); }
/** * Returns the pid for this process. * * @throws PidUnavailableException if parsing the pid from the name of the RuntimeMXBean fails * * @see java.lang.management.RuntimeMXBean#getName() */ public static int identifyPid() throws PidUnavailableException { return identifyPid(ManagementFactory.getRuntimeMXBean().getName()); }
protected void waitUntilProcessStops(final long timeout, final TimeUnit unit) { await() .untilAsserted(() -> assertThat(isProcessAlive(process)).isFalse()); }
protected static int identifyPid() { try { return ProcessUtils.identifyPid(); } catch (PidUnavailableException e) { if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e); } return 0; } }
protected void waitUntilProcessStops() { await().untilAsserted(() -> assertThat(isProcessAlive(process)).isFalse()); }
/** * Returns the process id of this {@code VM}. */ public int getPid() { return invoke(() -> ProcessUtils.identifyPid()); }
/** * Returns randomly unused pid between {@code lowerBound} (inclusive) and {@code upperBound} * (inclusive). */ public int findAvailablePid() throws TimeoutException { Stopwatch stopwatch = Stopwatch.createStarted(); int pid = random(); while (isProcessAlive(pid)) { if (stopwatch.elapsed(MILLISECONDS) > timeoutMillis) { throw new TimeoutException( "Failed to find available pid within " + timeoutMillis + " millis."); } pid = random(); } return pid; }
/** * Constructs a new ProcessLauncher. Parses this process's RuntimeMXBean name for the pid (process * id). * * @param pidFile the file to create and write pid into * @param force if true then the pid file will be replaced if it already exists * * @throws FileAlreadyExistsException if the pid file already exists and force is false * @throws IOException if unable to write pid (process id) to pid file * @throws PidUnavailableException if the pid cannot be parsed from the RuntimeMXBean name * * @see java.lang.management.RuntimeMXBean */ LocalProcessLauncher(final File pidFile, final boolean force) throws FileAlreadyExistsException, IOException, PidUnavailableException { notNull(pidFile, "Invalid pidFile '" + pidFile + "' specified"); this.pid = identifyPid(); this.pidFile = pidFile; writePid(force); }
private boolean shouldTerminate() throws InterruptedException { if (!ProcessUtils.isProcessAlive(process)) { if (!continueReading.isRunning()) { continueReading.start(); } else if (continueReading.elapsedTimeMillis() > continueReadingMillis) { return true; } } Thread.sleep(10); return false; }
boolean result = nativeProcessUtils.isProcessAlive(identifyPid()); if (result) { return nativeProcessUtils;
@Test public void findAvailablePidShouldNotReturnLivePid() throws Exception { int pid = availablePid.findAvailablePid(); assertThat(isProcessAlive(pid)).isFalse(); }
@Before public void before() throws Exception { mockParameters = mock(FileControllerParameters.class); pid = identifyPid(); timeout = 0; units = SECONDS; controller = new FileProcessController(mockParameters, pid, timeout, units); }
@Test public void lowerBoundShouldBeLegalPid() throws Exception { assertThat(isProcessAlive(DEFAULT_LOWER_BOUND)).isIn(true, false); }
@Before public void before() throws Exception { factory = new ProcessControllerFactory(); parameters = mock(ProcessControllerParameters.class); pid = identifyPid(); }