juce-framework / JUCE

JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins.
https://juce.com
Other
6.31k stars 1.67k forks source link

[Bug]: ChildProcess Leaves Zombies in Linux #1321

Closed mfisher31 closed 5 months ago

mfisher31 commented 6 months ago

Detailed steps on how to reproduce the bug

  1. Create a child process with juce::ChildProcess
  2. Let it die, or kill it with code.
  3. Look at system processes to see that it is now a zombie.
  4. This happens because SIGCHLD isn't implemented?

As a workaround I handle SIGCHLD like: signal(SIGCHLD, SIG_IGN); /* Silently (and portably) reap children. */

What is the expected behaviour?

Zombie processes not to be created when using juce::ChildProcess

Operating systems

Linux

What versions of the operating systems?

Any version of Linux probably, but I use Ubuntu 20.04

Architectures

x86_64, 64-bit

Stacktrace

No response

Plug-in formats (if applicable)

No response

Plug-in host applications (DAWs) (if applicable)

No response

Testing on the develop branch

I have not tested against the develop branch

Code of Conduct

szarvas commented 5 months ago

Thank you for reporting.

On Linux a terminated subprocess will not be cleaned up until its return value is collected. To do that "manually" one needs to call ChildProcess::isFinished() until it returns false or ChildProcess::waitForProcessToFinish() until it returns true.

With the following commit we added a helper class, ChildProcessManager, which will keep trying to collect the return value on a Timer callback, as long as the application is running.

To use this facility, you need to create and start your process with ChildProcessManager:: createAndStartManagedChildProcess.

https://github.com/juce-framework/JUCE/commit/0611baf1bead530fb0ec1998391dc251396b775a

mfisher31 commented 5 months ago

That's great, thank you!