From c9eb1b2cb37f4832a21c3aa8a422242023ecab97 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 8 Sep 2012 19:25:13 +0200 Subject: [PATCH] Better collection of zombie processes. Note that there seems to be a deadlock if a process exits when there are zombies around. Init also doesn't handle zombie children correctly as there is sent no SIGCHLD signal yet. --- utils/init.cpp | 4 +++- utils/mxsh.cpp | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/init.cpp b/utils/init.cpp index 4b7df9cc..fa67ebee 100644 --- a/utils/init.cpp +++ b/utils/init.cpp @@ -58,7 +58,9 @@ int runsystem() return status; } - return child(); + int ret = child(); + while ( 0 < waitpid(-1, NULL, WNOHANG) ); + return ret; } int main(int argc, char* argv[]) diff --git a/utils/mxsh.cpp b/utils/mxsh.cpp index ba0c72ee..3233de6b 100644 --- a/utils/mxsh.cpp +++ b/utils/mxsh.cpp @@ -79,6 +79,9 @@ int runcommandline(const char** tokens) bool internal; int internalresult; readcmd: + // Collect any pending zombie processes. + while ( 0 < waitpid(-1, NULL, WNOHANG) ); + cmdstart = cmdnext; for ( cmdend = cmdstart; true; cmdend++ ) {