h1234 has asked for the wisdom of the Perl Monks concerning the following question:
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"; } } ----------------------------------------
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Partial Zombie collection??
by hippo (Archbishop) on Aug 30, 2017 at 21:33 UTC | |
|
Re: Partial Zombie collection??
by locked_user sundialsvc4 (Abbot) on Aug 30, 2017 at 20:44 UTC | |
by h1234 (Initiate) on Aug 31, 2017 at 04:44 UTC | |
by karlgoethebier (Abbot) on Sep 01, 2017 at 11:51 UTC |