I've been researching perl and forking, and it seems like I'm doing everything correct, however my program doesn't seem to reap all the child processes, resulting in a bunch of zombies accumulating. The code has a master program, and then it looks like the zombies are being created in a supporting library. Sometimes Zombies are created using this subroutine, other times not. Other users of the program don't have any zombie issues, but my system does. I have no idea where to go, so I'd really appreciate any insight or suggestions that anyone can provide:

---------------------------------------- main.pl require 'library.pl'; $SIG{CHLD} = \&child_death; sub child_death { use POSIX ":sys_wait_h"; local ($!, $?); my $pid; do { $pid = waitpid( -1, WNOHANG ); print "reaped $pid" . ($? ? " with exit $?" : '') . "\n"; } until $pid <= 0; } ---------------------------------------- ---------------------------------------- library.pl &print_socket_fork_unix( $socket, $html, $close ); sub print_socket_fork_unix { my ( $socket, $html, $close ) = @_; my $pid = fork; if ( $? == -1 ) { print "$pid - Can't launch child: $!\n"; } elsif ( $? & 0x7F ) { print "$pid - Child killed by signal ".( $? & 0x7F )."\n"; } elsif ( $? >> 8 ) { print "$pid - Child exited with error ".( $? >> 8 )."\n"; } else { print "$pid - Child executed successfully\n"; } if ( defined $pid && $pid == 0 ) { print $socket $html; $socket->shutdown(2) if $close; $socket->close unless $close; print "$pid exiting process\n"; &POSIX::_exit(0) } else { shutdown( $socket, 0 ); print " $pid shutdown socket\n"; } } ----------------------------------------

In reply to Partial Zombie collection?? by h1234

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.