aboutsummaryrefslogtreecommitdiff
path: root/zencore/thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zencore/thread.cpp')
-rw-r--r--zencore/thread.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/zencore/thread.cpp b/zencore/thread.cpp
index c02bf508a..c92cca6de 100644
--- a/zencore/thread.cpp
+++ b/zencore/thread.cpp
@@ -334,16 +334,32 @@ ProcessMonitor::IsActive() const
bool
IsProcessRunning(int pid)
{
+ // This function is arguably not super useful, a pid can be re-used
+ // by the OS so holding on to a pid and polling it over some time
+ // period will not necessarily tell you what you probably want to know.
+
+#if ZEN_PLATFORM_WINDOWS
HANDLE hProc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
- if (hProc == NULL)
+ if (!hProc)
{
- return false;
+ DWORD Error = zen::GetLastError();
+
+ if (Error == ERROR_INVALID_PARAMETER)
+ {
+ return false;
+ }
+
+ using namespace fmt::literals;
+ ThrowSystemError(Error, "failed to open process with pid {}"_format(pid));
}
CloseHandle(hProc);
return true;
+#else
+ ZEN_NOT_IMPLEMENTED();
+#endif
}
int