From 0925b99e6d4734adeb67accff778c5fd68db3857 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 14 Dec 2011 14:18:45 +0000 Subject: [PATCH] Added ChildProcess::kill() --- modules/juce_core/native/juce_posix_SharedCode.h | 10 ++++++++++ modules/juce_core/native/juce_win32_Threads.cpp | 10 ++++++++++ modules/juce_core/threads/juce_ChildProcess.h | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/modules/juce_core/native/juce_posix_SharedCode.h b/modules/juce_core/native/juce_posix_SharedCode.h index e7678e82f3..483ffca081 100644 --- a/modules/juce_core/native/juce_posix_SharedCode.h +++ b/modules/juce_core/native/juce_posix_SharedCode.h @@ -1025,6 +1025,11 @@ public: return 0; } + bool killProcess() const + { + return ::kill (childPID, SIGKILL) == 0; + } + int childPID; private: @@ -1060,3 +1065,8 @@ int ChildProcess::readProcessOutput (void* dest, int numBytes) { return activeProcess != nullptr ? activeProcess->read (dest, numBytes) : 0; } + +bool ChildProcess::kill() +{ + return activeProcess == nullptr || activeProcess->killProcess(); +} diff --git a/modules/juce_core/native/juce_win32_Threads.cpp b/modules/juce_core/native/juce_win32_Threads.cpp index 067f17e16c..19694d2ca6 100644 --- a/modules/juce_core/native/juce_win32_Threads.cpp +++ b/modules/juce_core/native/juce_win32_Threads.cpp @@ -541,6 +541,11 @@ public: return total; } + bool killProcess() const + { + return TerminateProcess (processInfo.hProcess, 0) != FALSE; + } + bool ok; private: @@ -569,3 +574,8 @@ int ChildProcess::readProcessOutput (void* dest, int numBytes) { return activeProcess != nullptr ? activeProcess->read (dest, numBytes) : 0; } + +bool ChildProcess::kill() +{ + return activeProcess == nullptr || activeProcess->killProcess(); +} diff --git a/modules/juce_core/threads/juce_ChildProcess.h b/modules/juce_core/threads/juce_ChildProcess.h index 721ab8eb34..454a6c6cb5 100644 --- a/modules/juce_core/threads/juce_ChildProcess.h +++ b/modules/juce_core/threads/juce_ChildProcess.h @@ -74,6 +74,11 @@ public: /** Blocks until the process is no longer running. */ bool waitForProcessToFinish (int timeoutMs) const; + /** Attempts to kill the child process. + Returns true if it succeeded. Trying to read from the process after calling this may + result in undefined behaviour. + */ + bool kill(); private: //==============================================================================