2011/10/16 Dale Rahn <dr...@dalerahn.com>:
> 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 B  B  B 7 Mar 2011 14:59:06 -0000 B  B  B  1.15
> +++ usbhidaction.c B  B  B 15 Oct 2011 20:30:48 -0000
> @@ -30,6 +30,7 @@
> B * POSSIBILITY OF SUCH DAMAGE.
> B */
>
> +#include <sys/wait.h>
> B #include <stdio.h>
> B #include <stdlib.h>
> B #include <string.h>
> @@ -79,6 +80,19 @@ sighup(int signo)
> B  B  B  B reparse = 1;
> B }
>
> +static void
> +sigchild(int signo)
> +{
> + B  B  B  int status;
> + B  B  B  pid_t pid;
> + B  B  B  status = 0;
> + B  B  B  do {
> + B  B  B  B  B  B  B  pid = wait4(WAIT_ANY, &status, WNOHANG, NULL);
> + B  B  B  } while (pid != -1 && pid != 0);
> +
> + B  B  B  printf("child exited");
> +}
> +
> B int
> B main(int argc, char **argv)
> B {
> @@ -159,6 +173,7 @@ main(int argc, char **argv)
> B  B  B  B  B  B  B  B errx(1, "report too large");
>
> B  B  B  B (void)signal(SIGHUP, sighup);
> + B  B  B  (void)signal(SIGCHLD, sigchild);
>
> B  B  B  B if (demon) {
> B  B  B  B  B  B  B  B if (daemon(0, 0) < 0)

I just wanted to my own patch to the same problem in an hour. :)))

Maybe it's easier to just ignore SIGCHILD? Then no zombies will be
created at all, we don't care of them either.

I also proposed using fork(), to avoid usbhidaction waiting for app to
complete, which is, IMHO, dubious.
--
  WBR,
  Vadim Zhukov

Reply via email to