diff --git a/src/Core/WinSWCore/Util/ProcessHelper.cs b/src/Core/WinSWCore/Util/ProcessHelper.cs index f913480..5554a20 100644 --- a/src/Core/WinSWCore/Util/ProcessHelper.cs +++ b/src/Core/WinSWCore/Util/ProcessHelper.cs @@ -90,23 +90,32 @@ namespace winsw.Util /// If enabled, the perent process will be terminated before its children on all levels public static void StopProcessAndChildren(int pid, TimeSpan stopTimeout, bool stopParentProcessFirst) { - var childPids = GetChildPids(pid); - - if (stopParentProcessFirst) + List childPids = null; + try { - StopProcess(pid, stopTimeout); + childPids = GetChildPids(pid); + } + catch (Exception ex) + { + Logger.Warn("Failed to locate children of the process with PID=" + pid + ". Child processes won't be terminated", ex); + } + + if (!stopParentProcessFirst && childPids != null) + { foreach (var childPid in childPids) { StopProcessAndChildren(childPid, stopTimeout, stopParentProcessFirst); } } - else + + StopProcess(pid, stopTimeout); + + if (stopParentProcessFirst && childPids != null) { foreach (var childPid in childPids) { StopProcessAndChildren(childPid, stopTimeout, stopParentProcessFirst); } - StopProcess(pid, stopTimeout); } }