I have created 5 child process that I need to get the data they create back to the parent process. I am using socketpairs and they don't appear to be communicating. below is my program:
#!/usr/local/bin/perl
use IO::Handle;
use Socket;
my $i = 0; my $j = 0; my $pid;
my $DeadKid = 0;
%children = ();
sub REAPER
{
$SIG{CHLD} = \&REAPER;
$waitedpid = wait;
$DeadKid++;
delete $children{$pid};
}
sub HUNTSMAN
{
local($SIG{CHLD}) = 'ignore';
kill 'INT' => keys %children;
exit;
}
$SIG{CHLD} = \&REAPER;
$SIG{INT} = \&HUNTSMAN;
$query[0]="PollDhctSummary.ksh";
$query[1]="PollDhctVersions.ksh";
$query[2]="PollDhctBFS.ksh";
$query[3]="PollDhctMemory.ksh";
$query[4]="PollDhctMODInfo.ksh";
socketpair(CHILD, PARENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "sockectpair: $!";
CHILD->autoflush(1);
PARENT->autoflush(1);
for($i=0; $i < 5; $i++)
{
if ($pid=fork)
{
close PARENT;
$children{$pid}=1;
print "Kids Alive: $i\n";
}
elsif (defined $pid)
{
close CHILD;
$Output=`rsh -l dncs 10.253.0.1 "/pdt/bin/$query[$i] ip 10.1.37.58`;
while(1)
{
$test = <PARENT>;
{
print "Recieved from Parent: $test\n";
}
if($test == $i)
{
print PARENT $Output;
print "Sent to the Parent:$Output\n";
close PARENT;
exit 0;
}
sleep(2);
}
}
else
{
die "Cant fork! : $!\n";
}
}
$file = "/export/home/ccur/testout.txt";
open(INFO, ">$file"
;
for($j=0; $j < 5; $j++)
{
print CHILD $j;
print "Sent to the Child Process: $j\n";
$ParentTest = <CHILD>;
print "Recieved from Child: $ParentTest\n";
print INFO $ParentTest;
}
close CHILD;
close(INFO);
print "The End\n";
exit 0;
this is the out put it creates before I kill it.
bash$ test2.pl
Kids Alive: 0
Kids Alive: 1
Kids Alive: 2
Kids Alive: 3
Kids Alive: 4
Sent to the Child Process: 0
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
^Cbash$
Thanks in advance for your help. Randy
You can Email me at: RCooper@cinci.rr.com
#!/usr/local/bin/perl
use IO::Handle;
use Socket;
my $i = 0; my $j = 0; my $pid;
my $DeadKid = 0;
%children = ();
sub REAPER
{
$SIG{CHLD} = \&REAPER;
$waitedpid = wait;
$DeadKid++;
delete $children{$pid};
}
sub HUNTSMAN
{
local($SIG{CHLD}) = 'ignore';
kill 'INT' => keys %children;
exit;
}
$SIG{CHLD} = \&REAPER;
$SIG{INT} = \&HUNTSMAN;
$query[0]="PollDhctSummary.ksh";
$query[1]="PollDhctVersions.ksh";
$query[2]="PollDhctBFS.ksh";
$query[3]="PollDhctMemory.ksh";
$query[4]="PollDhctMODInfo.ksh";
socketpair(CHILD, PARENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "sockectpair: $!";
CHILD->autoflush(1);
PARENT->autoflush(1);
for($i=0; $i < 5; $i++)
{
if ($pid=fork)
{
close PARENT;
$children{$pid}=1;
print "Kids Alive: $i\n";
}
elsif (defined $pid)
{
close CHILD;
$Output=`rsh -l dncs 10.253.0.1 "/pdt/bin/$query[$i] ip 10.1.37.58`;
while(1)
{
$test = <PARENT>;
{
print "Recieved from Parent: $test\n";
}
if($test == $i)
{
print PARENT $Output;
print "Sent to the Parent:$Output\n";
close PARENT;
exit 0;
}
sleep(2);
}
}
else
{
die "Cant fork! : $!\n";
}
}
$file = "/export/home/ccur/testout.txt";
open(INFO, ">$file"
for($j=0; $j < 5; $j++)
{
print CHILD $j;
print "Sent to the Child Process: $j\n";
$ParentTest = <CHILD>;
print "Recieved from Child: $ParentTest\n";
print INFO $ParentTest;
}
close CHILD;
close(INFO);
print "The End\n";
exit 0;
this is the out put it creates before I kill it.
bash$ test2.pl
Kids Alive: 0
Kids Alive: 1
Kids Alive: 2
Kids Alive: 3
Kids Alive: 4
Sent to the Child Process: 0
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
Recieved from Parent:
^Cbash$
Thanks in advance for your help. Randy

You can Email me at: RCooper@cinci.rr.com