Merge branch '2.1.x' into 2.2.x

Closes gh-18940
This commit is contained in:
Andy Wilkinson 2019-11-08 13:32:49 +00:00
commit fc3f6a930d
1 changed files with 22 additions and 2 deletions

View File

@ -113,13 +113,33 @@ public class RunProcess {
* @return {@code true} if stopped
*/
public boolean handleSigInt() {
// if the process has just ended, probably due to this SIGINT, consider handled.
if (hasJustEnded()) {
if (allowChildToHandleSigInt()) {
return true;
}
return doKill();
}
private boolean allowChildToHandleSigInt() {
Process process = this.process;
if (process == null) {
return true;
}
long end = System.currentTimeMillis() + 5000;
while (System.currentTimeMillis() < end) {
if (!process.isAlive()) {
return true;
}
try {
Thread.sleep(500);
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
return false;
}
}
return false;
}
/**
* Kill this process.
*/