public boolean waitFor(final long timeout, final TimeUnit unit) throws InterruptedException {
    synchronized (this) {
      if (!started) {
        throw new IllegalStateException("Must be started before waitFor");
      }
    }

    final long startTime = System.nanoTime();

    long millisToJoin = unit.toMillis(timeout);
    stderr.join(millisToJoin);

    long nanosRemaining = unit.toNanos(timeout) - (System.nanoTime() - startTime);
    millisToJoin = unit.toMillis(nanosRemaining);
    stdout.join(millisToJoin);

    nanosRemaining = unit.toNanos(timeout) - (System.nanoTime() - startTime);
    return waitForProcess(nanosRemaining, unit);
  }
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