diff options
| author | Martin Ridgers <[email protected]> | 2021-11-09 16:52:17 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-11-09 16:52:17 +0100 |
| commit | 4bbf2bc8bbc0821abdffe9f85afcf02447e97d7b (patch) | |
| tree | b4cc665fe73ec241702da8ffaf0a893632ca3ddb | |
| parent | Implemented ProcessHandle::IsRunning() for Linux (diff) | |
| download | zen-4bbf2bc8bbc0821abdffe9f85afcf02447e97d7b.tar.xz zen-4bbf2bc8bbc0821abdffe9f85afcf02447e97d7b.zip | |
Implemented ProcessHandle::Terminate() for Linux
| -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? } |