diff --git a/src/main/java/com/aws/greengrass/util/platforms/unix/UnixExec.java b/src/main/java/com/aws/greengrass/util/platforms/unix/UnixExec.java index 314907acc8..b95fc45f86 100644 --- a/src/main/java/com/aws/greengrass/util/platforms/unix/UnixExec.java +++ b/src/main/java/com/aws/greengrass/util/platforms/unix/UnixExec.java @@ -123,7 +123,7 @@ public void close() throws IOException { for (PidProcess pp : pidProcesses) { pp.waitFor(gracefulShutdownTimeout.getSeconds(), TimeUnit.SECONDS); } - if (pidProcesses.stream().anyMatch(pidProcess -> { + boolean isAnyProcessAlive = pidProcesses.stream().anyMatch(pidProcess -> { try { return pidProcess.isAlive(); } catch (IOException ignored) { @@ -131,7 +131,8 @@ public void close() throws IOException { Thread.currentThread().interrupt(); } return false; - })) { + }); + if (isAnyProcessAlive) { logger.atWarn() .log("Command {} did not respond to interruption within timeout. Going to kill it now", this); diff --git a/src/main/java/com/aws/greengrass/util/platforms/unix/UnixPlatform.java b/src/main/java/com/aws/greengrass/util/platforms/unix/UnixPlatform.java index cc5bf42291..6ba2d8ece6 100644 --- a/src/main/java/com/aws/greengrass/util/platforms/unix/UnixPlatform.java +++ b/src/main/java/com/aws/greengrass/util/platforms/unix/UnixPlatform.java @@ -275,13 +275,13 @@ public UnixUserAttributes lookupCurrentUser() throws IOException { public Set killProcessAndChildren(Process process, boolean force, Set additionalPids, UserDecorator decorator) throws IOException, InterruptedException { - PidProcess pp = Processes.newPidProcess(process); + PidProcess parentPidProcess = Processes.newPidProcess(process); - logger.atInfo().log("Killing child processes of pid {}, force is {}", pp.getPid(), force); + logger.atInfo().log("Killing child processes of pid {}, force is {}", parentPidProcess.getPid(), force); Set pids; try { pids = getChildPids(process); - logger.atDebug().log("Found children of {}. {}", pp.getPid(), pids); + logger.atDebug().log("Found children of {}. {}", parentPidProcess.getPid(), pids); if (additionalPids != null) { pids.addAll(additionalPids); } @@ -293,6 +293,9 @@ public Set killProcessAndChildren(Process process, boolean force, Set killProcessAndChildren(Process process, boolean force, Set