From 4bbf2bc8bbc0821abdffe9f85afcf02447e97d7b Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Tue, 9 Nov 2021 16:52:17 +0100 Subject: Implemented ProcessHandle::Terminate() for Linux --- zencore/thread.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'zencore/thread.cpp') 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 # include +# include # include #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? } -- cgit v1.2.3