FORK: {
if ($pid = fork) {
#Parent here.
#Child process pid is available in $pid
} elsif (defined $pid) { #pid is zero here if defined
#child here
#parent process pid is available with getppid (Not available with Windows).
} elsif ($! == EAGAIN) {
#EAGAIN is supposedly recoverable fork error
sleep 5;
redo FORK;
} else {
#Weird fork error
die "Can't fork: $!\n";
}
}
####
if (open(TO, "|-")) {
print TO $fromparent;
} else {
$tochild = ;
#Do whatever with $child
exit;
};
####
pipe(FROM_PARENT, TO_CHILD) or die "pipe: $!";
select((select(TO_CHILD), $| = 1))[0]);