Avoid interference with other users of waitpid.
Instead of using waitpid(-1), explicitly waits on all known processes. This is inefficient for large numbers of child processes, but seems to be the only way to ensure to not interfere with other code that uses waitpid().
This commit is contained in:
parent
72234fc0a7
commit
4724f14145
|
@ -273,12 +273,18 @@ final class SignalEventDriverProcesses(Loop : PosixEventLoop) : EventDriverProce
|
||||||
}
|
}
|
||||||
|
|
||||||
// instead, use waitpid to determine all exited processes
|
// instead, use waitpid to determine all exited processes
|
||||||
while (true) {
|
ProcessID[] allprocs;
|
||||||
int status;
|
() @trusted {
|
||||||
auto ret = () @trusted { return waitpid(-1, &status, WNOHANG); } ();
|
try synchronized (StaticProcesses.m_mutex)
|
||||||
if (ret <= 0) break;
|
allprocs = StaticProcesses.m_processes.keys;
|
||||||
|
catch (Exception e) assert(false, e.msg);
|
||||||
|
} ();
|
||||||
|
|
||||||
onProcessExit(ret, () @trusted { return WEXITSTATUS(status); } ());
|
foreach (pid; allprocs) {
|
||||||
|
int status;
|
||||||
|
auto ret = () @trusted { return waitpid(cast(int)pid, &status, WNOHANG); } ();
|
||||||
|
if (ret == cast(int)pid)
|
||||||
|
onProcessExit(ret, () @trusted { return WEXITSTATUS(status); } ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue