From cc60286c89741d3840ac3c8cb6c86ebf9eb16bb5 Mon Sep 17 00:00:00 2001 From: attila Date: Fri, 5 Jan 2024 17:24:27 +0100 Subject: [PATCH] ConnectedChildProcess: Wait for process termination on Linux to not leave zombies This change also avoids the AudioPluginHost leaving zombie child processes behind. --- .../interprocess/juce_ConnectedChildProcess.cpp | 15 +++++++++++++-- .../interprocess/juce_ConnectedChildProcess.h | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp b/modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp index 95a6b06630..f671fdaa79 100644 --- a/modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp +++ b/modules/juce_events/interprocess/juce_ConnectedChildProcess.cpp @@ -164,9 +164,20 @@ bool ChildProcessCoordinator::launchWorkerProcess (const File& executable, const args.add (executable.getFullPathName()); args.add (getCommandLinePrefix (commandLineUniqueID) + pipeName); - childProcess.reset (new ChildProcess()); + childProcess = [&]() -> std::shared_ptr + { + if ((SystemStats::getOperatingSystemType() & SystemStats::Linux) != 0) + return ChildProcessManager::getInstance()->createAndStartManagedChildProcess (args, streamFlags); + + auto p = std::make_shared(); + + if (p->start (args, streamFlags)) + return p; + + return nullptr; + }(); - if (childProcess->start (args, streamFlags)) + if (childProcess != nullptr) { connection.reset (new Connection (*this, pipeName, timeoutMs <= 0 ? defaultTimeoutMs : timeoutMs)); diff --git a/modules/juce_events/interprocess/juce_ConnectedChildProcess.h b/modules/juce_events/interprocess/juce_ConnectedChildProcess.h index bf803483b6..2883b5ecdc 100644 --- a/modules/juce_events/interprocess/juce_ConnectedChildProcess.h +++ b/modules/juce_events/interprocess/juce_ConnectedChildProcess.h @@ -215,7 +215,7 @@ public: bool sendMessageToSlave (const MemoryBlock& mb) { return sendMessageToWorker (mb); } private: - std::unique_ptr childProcess; + std::shared_ptr childProcess; struct Connection; std::unique_ptr connection;