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: //==============================================================================