Here is my code:
my $child = my $parent = my $pid = undef;
# Create a socket pair from IPC (both ways)
if (!socketpair($child, $parent, AF_UNIX, SOCK_STREAM, PF_UNSPEC))
+ {
die "socketpair failed: ".$!;
}
else {
# Flush messages immediately
$child->autoflush(1);
$parent->autoflush(1);
if (!defined($pid = fork())) {
die "Fork failed: ".$!;
}
elsif ($pid == 0) {
close($child);
# Here the process will carry out the work, and also write
+ to the 'pipe'
# It will only exit this loop upon SIGTERM
# Close the pipe with the parent
close($parent);
exit 0;
}
else {
close($parent);
}
}
The pipe signal only occurs after a long period of inactivity on the client side, not on the server side (which also uses the 'pipe' to send messages to the client)