---------------------------------------- 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"; } } ----------------------------------------