fix(process): fork_detached created zombie processes

Since the forked processes are still our children, we need to wait on
them, otherwise they become zombie processes.

We now fork twice, let the first fork immediately return and wait on it.
This reparents the second fork, which runs the actual code, to the init
process which then collects it.

Ref #770
This commit is contained in:
patrick96
2020-12-12 02:21:36 +01:00
committed by Patrick Ziegler
parent ccf14d9816
commit 47483a94f1
4 changed files with 65 additions and 13 deletions

View File

@ -33,7 +33,7 @@ command<output_policy::IGNORED>::~command() {
* Execute the command
*/
int command<output_policy::IGNORED>::exec(bool wait_for_completion) {
m_forkpid = process_util::fork_detached([m_cmd = m_cmd] { process_util::exec_sh(m_cmd.c_str()); });
m_forkpid = process_util::spawn_async([m_cmd = m_cmd] { process_util::exec_sh(m_cmd.c_str()); });
if (wait_for_completion) {
auto status = wait();
m_forkpid = -1;