aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/process.cpp')
-rw-r--r--src/zencore/process.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/zencore/process.cpp b/src/zencore/process.cpp
index e0a395494..d8be0d343 100644
--- a/src/zencore/process.cpp
+++ b/src/zencore/process.cpp
@@ -661,14 +661,13 @@ IsProcessRunning(int pid)
if (!hProc)
{
DWORD Error = zen::GetLastError();
-
if (Error == ERROR_INVALID_PARAMETER)
{
return false;
}
-
ThrowSystemError(Error, fmt::format("failed to open process with pid {}", pid));
}
+ auto _ = MakeGuard([hProc]() { CloseHandle(hProc); });
bool bStillActive = true;
DWORD ExitCode = 0;
@@ -678,14 +677,25 @@ IsProcessRunning(int pid)
}
else
{
- ZEN_WARN("Unable to get exit code from handle for process '{}', treating the process as active", pid);
+ DWORD Error = GetLastError();
+ ThrowSystemError(Error, fmt::format("failed to get process exit code for pid {}", pid));
}
-
- CloseHandle(hProc);
-
return bStillActive;
#elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
- return (kill(pid_t(pid), 0) == 0);
+ int Res = kill(pid_t(pid), 0);
+ if (Res == 0)
+ {
+ return true;
+ }
+ int Error = errno;
+ if (Error == ESRCH) // No such process
+ {
+ return false;
+ }
+ else
+ {
+ ThrowSystemError(Error, fmt::format("Failed to signal running process %d: %d", pid, Error));
+ }
#endif
}