my $fork_num = ( $#hostlist <= MAXFORK ? $#hostlist : MAXFORK ); for ( 0..$fork_num ) { ## ## create bi-directional socket for parent/child communication my $to_child = IO::Socket->new(); my $to_parent = IO::Socket->new(); socketpair($to_child, $to_parent, PF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "Couldn't create socket pair: $!\n"; my $pid; if ( $pid = fork ) { ### parent process undef $to_parent; $to_child->autoflush; $children{$pid} = $to_child; sleep 1; next; } else { ### child process undef $to_child; undef %children; $to_parent->autoflush(1); local $SIG{PIPE} = sub { print " CAUGHT PIPE\n\n"; die "Signal caught in Child $$: $!\n"; }; ## ## main processing occurs in the subroutine. &process_config_job($fork_num, $to_parent); } }