From 236bd0b7788f3bf34d770f86085ad326f9dd06aa Mon Sep 17 00:00:00 2001 From: NextTurn <45985406+NextTurn@users.noreply.github.com> Date: Thu, 29 Nov 2018 00:00:00 +0800 Subject: [PATCH] Check start time of child processes --- src/Core/WinSWCore/Util/ProcessHelper.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Core/WinSWCore/Util/ProcessHelper.cs b/src/Core/WinSWCore/Util/ProcessHelper.cs index f062c0c..644404c 100644 --- a/src/Core/WinSWCore/Util/ProcessHelper.cs +++ b/src/Core/WinSWCore/Util/ProcessHelper.cs @@ -21,12 +21,18 @@ namespace winsw.Util /// /// Process PID /// List of child process PIDs - private static unsafe List GetChildProcesses(int processId) + private static unsafe List GetChildProcesses(DateTime startTime, int processId) { var children = new List(); foreach (Process process in Process.GetProcesses()) { + if (process.StartTime <= startTime) + { + process.Dispose(); + continue; + } + IntPtr handle; try { @@ -118,7 +124,7 @@ namespace winsw.Util { StopProcess(process, stopTimeout); - foreach (Process child in GetChildProcesses(process.Id)) + foreach (Process child in GetChildProcesses(process.StartTime, process.Id)) { StopProcessTree(child, stopTimeout); }