code: public int waitForExit(final Deadline deadline)
  	{
  		final int intervalMax = 4500; // the maximum time between polls is 4.5 seconds
  		int interval = 5; // initial sleep will be 3* this, so 15ms
  
  		while (!isFinished() && deadline.isValid())
  		{
  			try
  			{
  				// Check very frequently initially, tripling the wait each time
  				// this allows us to return very quickly for short-running processes, but not hammer the CPU for long-running processes
  				if (interval != intervalMax)
  				{
  					interval = Math.min(interval * 3, intervalMax);
  				}
  
  				final boolean hasExited = this.process.waitFor(Math.min(deadline.getTimeLeft(), interval), TimeUnit.MILLISECONDS);
  
  				if (hasExited)
  				{
  					// Wait for the deadline to expire or for any output reading to complete
  					while (deadline.isValid() && isStillReadingOutput())
  						new Timeout(10, TimeUnit.MILLISECONDS).sleep();
  
  					return exitCode();
  				}
  			}
  			catch (InterruptedException e)
  			{
  			}
  		}
  
  		if (deadline.isExpired())
  			return Integer.MIN_VALUE;
  		else
  			return exitCode();
  	}
docs: Waits for the process to exit; this method blocks until the process has completed (at which point it returns the process
  exit code) or until <code>deadline</code> has elapsed, at which point it returns Integer.MIN_VALUE
  
  @param deadline
  
  @return the exit code of the process