I first wrote this a while back but it got lost in my trees after I
updated to a recent snapshot I noticed I was out of processes again,
that I had > 50 zombie processes sitting around.
I use usbhidaction to play/stop/skip music playing on my desktop
controlling xmms.
Without this patch, each time a key was pressed and xmms ran/exited it
would leave another zombie process.
Index: usbhidaction.c
===================================================================
RCS file: /cvs/src/usr.bin/usbhidaction/usbhidaction.c,v
retrieving revision 1.15
diff -u -p -r1.15 usbhidaction.c
--- usbhidaction.c 7 Mar 2011 14:59:06 -0000 1.15
+++ usbhidaction.c 15 Oct 2011 20:30:48 -0000
@@ -30,6 +30,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -79,6 +80,19 @@ sighup(int signo)
reparse = 1;
}
+static void
+sigchild(int signo)
+{
+ int status;
+ pid_t pid;
+ status = 0;
+ do {
+ pid = wait4(WAIT_ANY, &status, WNOHANG, NULL);
+ } while (pid != -1 && pid != 0);
+
+ printf("child exited");
+}
+
int
main(int argc, char **argv)
{
@@ -159,6 +173,7 @@ main(int argc, char **argv)
errx(1, "report too large");
(void)signal(SIGHUP, sighup);
+ (void)signal(SIGCHLD, sigchild);
if (demon) {
if (daemon(0, 0) < 0)
Dale Rahn [email protected]