diff options
| author | zousar <[email protected]> | 2023-06-27 01:50:28 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-06-27 09:50:28 +0200 |
| commit | c45e309cee3580b5c7f0632e2993107827f08515 (patch) | |
| tree | 3a15f22c51f72cfca3ea135cca98a60a048374dc /src/zencore/thread.cpp | |
| parent | 0.2.14-pre2 (diff) | |
| download | zen-c45e309cee3580b5c7f0632e2993107827f08515.tar.xz zen-c45e309cee3580b5c7f0632e2993107827f08515.zip | |
Fix IsProcessRunning on Windows (#335)
IsProcessRunning on Windows would only consider if we could get a handle to a process. It is possible to get a handle to a process even if it is terminated in Windows. To actually know if the process is running, a further call to GetExitCodeProces is required. Addressing this issue ensures that the ZenServerState::Sweep method doesn't keep terminated processes in the state table.
Diffstat (limited to 'src/zencore/thread.cpp')
| -rw-r--r-- | src/zencore/thread.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp index 67a0878d0..a44c0ee90 100644 --- a/src/zencore/thread.cpp +++ b/src/zencore/thread.cpp @@ -1065,9 +1065,20 @@ IsProcessRunning(int pid) ThrowSystemError(Error, fmt::format("failed to open process with pid {}", pid)); } + bool bStillActive = true; + DWORD ExitCode = 0; + if (0 != GetExitCodeProcess(hProc, &ExitCode)) + { + bStillActive = ExitCode == STILL_ACTIVE; + } + else + { + ZEN_WARN("Unable to get exit code from handle for process '{}', treating the process as active", pid); + } + CloseHandle(hProc); - return true; + return bStillActive; #elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC return (kill(pid_t(pid), 0) == 0); #endif |