carelessly left them behind.
- * $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
*
*
* Wait until prodded by another X client
*
/*----- Revision history --------------------------------------------------*
*
* $Log: xwait.c,v $
/*----- 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.
*
* Revision 1.1 1998/11/16 23:00:49 mdw
* Initial versions.
*
/*----- Header files ------------------------------------------------------*/
/*----- Header files ------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <unistd.h>
#include <X11/Xlib.h>
/*----- Main code ---------------------------------------------------------*/
/*----- Main code ---------------------------------------------------------*/
+/* --- @sigchld@ --- */
+
+static void sigchld(int sig)
+{
+ while (waitpid(-1, 0, WNOHANG) > 0)
+ ;
+}
+
+/* --- @main@ --- */
+
int main(int argc, char *argv[])
{
char *display = 0;
int main(int argc, char *argv[])
{
char *display = 0;
+ /* --- 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 (;;) {
/* --- Now wait for an event --- */
for (;;) {