Correzioni varie al codice ed alle relative citazioni
[gapil.git] / sources / HandSIGCHLD.c
diff --git a/sources/HandSIGCHLD.c b/sources/HandSIGCHLD.c
new file mode 100644 (file)
index 0000000..04f9753
--- /dev/null
@@ -0,0 +1,27 @@
+#include <errno.h>       /* error simbol definitions */
+#include <signal.h>      /* signal handling declarations */
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "macros.h"
+
+void HandSIGCHLD(int sig)
+{
+    int errno_save;
+    int status;
+    pid_t pid;
+    /* save errno current value */
+    errno_save = errno;
+    /* loop until no */
+    do {
+       errno = 0;
+       pid = waitpid(WAIT_ANY, &status, WNOHANG);
+       if (pid > 0) {
+           debug("child %d terminated with status %x\n", pid, status);
+       }
+    } while ((pid > 0) && (errno == EINTR));
+    /* restore errno value*/
+    errno = errno_save;
+    /* return */
+    return;
+}