in reply to nite of the living dead: perl and stunnel make zombies

Setting $SIG{CHLD} to 'IGNORE' will certainly allow zombies to be created. The reason they're there is because the parent has not (through omission or inability) called wait (or waitpid) to acknowledge the child's death. Something simple like this should work:
$SIG{CHLD} = sub { wait };
This needs to be set before (execution-wise) any fork is done.

Update: I am working under the assumption that your description of "a zombie" being left behind was accurate. If there's a chance that you'll get multiple child deaths rapidly, merlyn explains below that this is not sufficient. Regardless, the "standard" REAPER function that you said you were using should have worked in the first place. I am suspicious that $SIG{CHLD} isn't being declared in the correct place or is being localized unnecessarily.

Replies are listed 'Best First'.
Re: Re: nite of the living dead: perl and stunnel make zombies
by merlyn (Sage) on Nov 22, 2000 at 03:42 UTC
    That's neither necessary nor sufficient.

    The problem is that you might get one SIGCHLD even though more than one child has gone belly up, and thus you aren't waiting long enough.

    Either use a double-fork solution (so the kids are effectively orphaned grandkids who become adopted by process #1), or a waitpid loop until there are no more kids to reap at opportune times in your algorithm.

    -- Randal L. Schwartz, Perl hacker

      One method to do the latter:
      use POSIX ":sys_wait_h"; SIG{CHLD} = \&REAPER; sub REAPER { 1 while (waitpid(-1,&WNOHANG) != -1); $SIG{CHLD} = \&REAPER; }
      On a somewhat off-topic note, what version of the perldocs (like this one) are the ones on PerlMonks? 5.6's waitpid docs have an example of exactly this, whereas 'tis missing on PerlMonks..
      perl -e 'print "Just use $^X$\"$]!$/"'
        I don't think vroom has reimported the pdocs since 5.6 settled. They are eldritch. =)

        --
        $you = new YOU;
        honk() if $you->love(perl)

(tye)Re: nite of the living dead: perl and stunnel make zombies
by tye (Sage) on Nov 22, 2000 at 03:12 UTC

    That actually depends on what operating system you are using. System-V-based Unix let you say $SIG{CHLD}='IGNORE' when you mean "I don't care about watching my children die so just clean up the mess and don't bother me" which means you get no zombies. BSD-ish Unix doesn't.

            - tye (but my friends call me "Tye")