Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

socketpair on unix solaris e450

Status
Not open for further replies.

randy4126

Programmer
Jun 2, 2001
62
US
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 &quot;Kids Alive: $i\n&quot;;
}
elsif (defined $pid)
{
close CHILD;

$Output=`rsh -l dncs 10.253.0.1 &quot;/pdt/bin/$query[$i] ip 10.1.37.58`;
while(1)
{
$test = <PARENT>;
{
print &quot;Recieved from Parent: $test\n&quot;;
}
if($test == $i)
{
print PARENT $Output;
print &quot;Sent to the Parent:$Output\n&quot;;
close PARENT;
exit 0;
}
sleep(2);
}
}
else
{
die &quot;Cant fork! : $!\n&quot;;
}
}

$file = &quot;/export/home/ccur/testout.txt&quot;;
open(INFO, &quot;>$file&quot;);
for($j=0; $j < 5; $j++)
{
print CHILD $j;
print &quot;Sent to the Child Process: $j\n&quot;;
$ParentTest = <CHILD>;
print &quot;Recieved from Child: $ParentTest\n&quot;;
print INFO $ParentTest;
}

close CHILD;
close(INFO);

print &quot;The End\n&quot;;

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
smiletiniest.gif


You can Email me at: RCooper@cinci.rr.com
 
I gues what I need to know is there any buffering when you are useing socket pairs or does child have to be listening when the parent and vise versa. I know its a FIFO queue so I think it does have to be buffered but I still can't get it to work. Randy
smiletiniest.gif


You can Email me at: RCooper@cinci.rr.com
 
I got it figured out. The wrong child was reading what i was sending and clearing the buffer. So I added a resend routine and it worked great. Randy
smiletiniest.gif


You can Email me at: RCooper@cinci.rr.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top