private int waitForExitValue(final Process p)
      throws InterruptedException {
    log.debug("Waiting for the exit value for process {}", p);
    Thread t = new Thread(new Runnable() {
      @Override
      public void run() {
        try {
          p.waitFor();
        } catch (InterruptedException ignore) {
          Thread.currentThread().interrupt();
          return;
        }
      }
    });

    t.start();
    try {
      t.join(TimeUnit.MILLISECONDS.convert(getScriptTimeoutS(), TimeUnit.SECONDS));
    } catch (InterruptedException e) {
      t.interrupt();
      throw new SamzaException("Timeout running shell command", e);
    }

    int exitVal = p.exitValue();
    log.debug("Exit value {}", exitVal);
    return exitVal;
  }
Waits for a finite time interval for the script to complete.

@param p                     the process on which this method will wait.
@return                      the exit code returned by the process.
@throws InterruptedException if the thread is interrupted while waiting for the process to finish.
samza-rest/src/main/java/org/apache/samza/rest/script/ScriptRunner.java