diff options
| author | Stefan Boberg <[email protected]> | 2021-09-17 23:15:56 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-17 23:15:56 +0200 |
| commit | 28de689b30b64c0c2691b05866c27c84e0a21ff3 (patch) | |
| tree | ec54dc70fe64407e2cd16347224239b9ba8f9703 /zencore/thread.cpp | |
| parent | Added ThrowSystemError() helper (diff) | |
| download | zen-28de689b30b64c0c2691b05866c27c84e0a21ff3.tar.xz zen-28de689b30b64c0c2691b05866c27c84e0a21ff3.zip | |
IsProcessRunning now throws if it fails the function fails to get a handle to the process due to an error (unless it is because the process does not exist)
Diffstat (limited to 'zencore/thread.cpp')
| -rw-r--r-- | zencore/thread.cpp | 20 |
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 |