private boolean waitForProcess(final long timeout, final TimeUnit unit)
      throws InterruptedException {
    long startTime = System.nanoTime();
    long nanosRemaining = unit.toNanos(timeout);

    while (nanosRemaining > 0) {
      try {
        process.exitValue();
        return true;
      } catch (IllegalThreadStateException ex) {
        if (nanosRemaining > 0) {
          long millisToSleep = Math.min(TimeUnit.NANOSECONDS.toMillis(nanosRemaining) + 1, 100);
          Thread.sleep(millisToSleep);
        }
      }
      nanosRemaining = unit.toNanos(timeout) - (System.nanoTime() - startTime);
    }
    return false;
  }
Starts the stdout and stderr reader threads for a running process. Provides a mechanism to
waitFor the process to terminate.
<p>
Extracted from ProcessWrapper.
geode-junit/src/main/java/org/apache/geode/test/process/ProcessOutputReader.java