From a5676fcdcfe2ed60d3e5ff933f210ba49df9437e Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Sun, 16 Dec 2007 20:34:49 +0000 Subject: [PATCH] patch by Pieter Grimmerink: -call waitpid on the child, after it completes. This avoids zombies. --- lib/base/console.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/base/console.cpp b/lib/base/console.cpp index 3f73fba1..1e391e17 100644 --- a/lib/base/console.cpp +++ b/lib/base/console.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include int bidirpipe(int pfd[], char *cmd , char *argv[]) { @@ -222,7 +224,11 @@ void eConsoleAppContainer::kill() { eDebug("user kill(SIGKILL) console App"); killstate=-1; - ::kill(pid, SIGKILL); + /* + * Use a negative pid value, to signal the whole process group + * ('pid' might not even be running anymore at this point) + */ + ::kill(-pid, SIGKILL); closePipes(); } while( outbuf.size() ) // cleanup out buffer @@ -242,7 +248,11 @@ void eConsoleAppContainer::sendCtrlC() if ( killstate != -1 && pid != -1 ) { eDebug("user send SIGINT(Ctrl-C) to console App"); - ::kill(pid, SIGINT); + /* + * Use a negative pid value, to signal the whole process group + * ('pid' might not even be running anymore at this point) + */ + ::kill(-pid, SIGINT); } } @@ -301,7 +311,20 @@ void eConsoleAppContainer::readyRead(int what) { eDebug("child has terminated"); closePipes(); - /*emit*/ appClosed(killstate); + int childstatus; + int retval = killstate; + /* + * We have to call 'wait' on the child process, in order to avoid zombies. + * Also, this gives us the chance to provide better exit status info to appClosed. + */ + if (::waitpid(pid, &childstatus, 0) > 0) + { + if (WIFEXITED(childstatus)) + { + retval = WEXITSTATUS(childstatus); + } + } + /*emit*/ appClosed(retval); } } -- 2.30.2