Glodalec <> wrote:
> > print $TOCHILD "The child will read this on its STDIN";
> THanks for advice. How about a child exec, which should actually write
> to parent's SESSION handler (got from accept()), instead of its own
> STDOUT.?
It's probably easiest to do that manually, viz (untested):
accept my $NEWCONN, $LISTENER or die "accept failed: $!";
# or you'd probably be better off using IO::Socket::INET
my $NEWCONN = $LISTENER->accept or die "accept failed: $!";
pipe my ($FROMPARENT, $TOCHILD) or die "pipe failed: $!";
my $pid = fork;
defined $pid or die "fork failed: $!";
unless ($pid) {
open STDIN, '<&', $FROMPARENT or die "dup2 to STDIN failed: $!";
open STDOUT, '>&', $NEWCONN or die "dup2 to STDOUT failed: $!";
exec 'A.pl' or die "exec failed: $!";
}
close $FROMPARENT;
close $NEWCONN;
Obviously you want to put all this in a sub, so you can say
my $TOCHILD = accept_new_child($LISTENER);
If you get errors from the open '<&' syntax, you may need a newer
version of perl; or you can replace them with
open STDIN, '<&' . fileno $FROMPARENT or ...
Ben
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~
~ Jorge Luis Borges, 'The Babylon Lottery'