From: mdw Date: Wed, 18 Nov 1998 21:25:06 +0000 (+0000) Subject: Reap dead children as they arrive. The previous shell may have X-Git-Tag: 1.0.1~3 X-Git-Url: https://git.distorted.org.uk/~mdw/xtoys/commitdiff_plain/203d0643442daebb70dc732a2aeff403154451b7 Reap dead children as they arrive. The previous shell may have carelessly left them behind. --- diff --git a/xwait.c b/xwait.c index 7142217..45bb426 100644 --- a/xwait.c +++ b/xwait.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: xwait.c,v 1.1 1998/11/16 23:00:49 mdw Exp $ + * $Id: xwait.c,v 1.2 1998/11/18 21:25:06 mdw Exp $ * * Wait until prodded by another X client * @@ -29,6 +29,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: xwait.c,v $ + * Revision 1.2 1998/11/18 21:25:06 mdw + * Reap dead children as they arrive. The previous shell may have + * carelessly left them behind. + * * Revision 1.1 1998/11/16 23:00:49 mdw * Initial versions. * @@ -36,10 +40,13 @@ /*----- Header files ------------------------------------------------------*/ +#include #include #include #include +#include +#include #include #include @@ -49,6 +56,16 @@ /*----- Main code ---------------------------------------------------------*/ +/* --- @sigchld@ --- */ + +static void sigchld(int sig) +{ + while (waitpid(-1, 0, WNOHANG) > 0) + ; +} + +/* --- @main@ --- */ + int main(int argc, char *argv[]) { char *display = 0; @@ -135,6 +152,23 @@ int main(int argc, char *argv[]) } } + /* --- Set up a handler when children die --- * + * + * I don't fork any children? Why is this useful? Because I've been + * execed from a shell which started lots of background processes, and + * they'll zombie themselves otherwise. + */ + + { + struct sigaction sa; + + sa.sa_handler = sigchld; + sigemptyset(&sa.sa_mask); + sigaddset(&sa.sa_mask, SIGCHLD); + sa.sa_flags = 0; + sigaction(SIGCHLD, &sa, 0); + } + /* --- Now wait for an event --- */ for (;;) {