diff options
Diffstat (limited to 'zencore/thread.cpp')
| -rw-r--r-- | zencore/thread.cpp | 18 |
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? } |