aboutsummaryrefslogtreecommitdiff
path: root/zencore/thread.cpp
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-11-09 16:52:17 +0100
committerMartin Ridgers <[email protected]>2021-11-09 16:52:17 +0100
commit4bbf2bc8bbc0821abdffe9f85afcf02447e97d7b (patch)
treeb4cc665fe73ec241702da8ffaf0a893632ca3ddb /zencore/thread.cpp
parentImplemented ProcessHandle::IsRunning() for Linux (diff)
downloadzen-4bbf2bc8bbc0821abdffe9f85afcf02447e97d7b.tar.xz
zen-4bbf2bc8bbc0821abdffe9f85afcf02447e97d7b.zip
Implemented ProcessHandle::Terminate() for Linux
Diffstat (limited to 'zencore/thread.cpp')
-rw-r--r--zencore/thread.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/zencore/thread.cpp b/zencore/thread.cpp
index 3cb126d87..452ec6079 100644
--- a/zencore/thread.cpp
+++ b/zencore/thread.cpp
@@ -14,6 +14,7 @@
# include <mutex>
# include <pthread.h>
+# include <signal.h>
# include <unistd.h>
#endif
@@ -370,14 +371,25 @@ ProcessHandle::IsValid() const
void
ProcessHandle::Terminate(int ExitCode)
{
- if (IsRunning())
+ if (!IsRunning())
{
- TerminateProcess(m_ProcessHandle, ExitCode);
+ return;
}
+ bool bSuccess = false;
+
+#if ZEN_PLATFORM_WINDOWS
+ TerminateProcess(m_ProcessHandle, ExitCode);
DWORD WaitResult = WaitForSingleObject(m_ProcessHandle, INFINITE);
+ bSuccess = (WaitResult != WAIT_OBJECT_0);
+#elif ZEN_PLATFORM_LINUX
+ ZEN_UNUSED(ExitCode);
+ bSuccess = (kill(m_Pid, SIGKILL) == 0);
+#else
+# error Check kill() on this platform
+#endif
- if (WaitResult != WAIT_OBJECT_0)
+ if (!bSuccess)
{
// What might go wrong here, and what is meaningful to act on?
}