private boolean waitForProcessTermination(Process process, long timeout) throws InterruptedException {
    long startTime = System.currentTimeMillis();
    do {
      try {
        process.exitValue();
        return true;
      } catch (IllegalThreadStateException ignored) {}
      // Check if process has terminated once per second
      Thread.sleep(1000);
    } while (System.currentTimeMillis() - startTime < timeout);
    return false;
  }
Waits until the process has terminated or waiting time elapses.
@param timeout time to wait in miliseconds
@return true if process has exited, false otherwise
ambari-server/src/main/java/org/apache/ambari/server/bootstrap/BSRunner.java