<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">Like I said, just flip the content between the two routines.&nbsp; I hadda tweak a bit because you can't have both waiting in a while loop or they both wait forever so I just sent a single line from the parent down.&nbsp; And keep in mind, the output looks screwy because the parents will be in order, but the children fire somewhat randomly between depending on when they execute their code.<br><br>SW<br><br>----- Original Message ----<br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">From: Mike Ward &lt;unforgiven24@gmail.com&gt;<br><br>I wouldn't mind looking at the two-directional code as well, if it's no trouble. <br><br><div class="gmail_quote"><blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">--------------------------- cut here -----------------------------<br>
#!/usr/bin/perl<br>
<br>
use Socket;<br>
use IO::Handle;<br>
<br>
my (@c,@p,@pid); # c=child handle, p=parent handle, pid=process ID<br>
for(my $s=0; $s&lt;5; $s++) {<br>
 &nbsp;$c[$s] = new IO::Handle;<br>
 &nbsp;$p[$s] = new IO::Handle;<br>
<br>
 &nbsp;socketpair($c[$s], $p[$s], AF_UNIX, SOCK_STREAM, PF_UNSPEC)<br>
 &nbsp; &nbsp;or &nbsp;die "socketpair: $!";<br>
<br>
 &nbsp;$c[$s]-&gt;autoflush(1);<br>
 &nbsp;$p[$s]-&gt;autoflush(1);<br>
<br>
<br>
 &nbsp;if ($pid[$s] = fork()) { # is the parent<br>
 &nbsp; &nbsp;close $p[$s]; &nbsp; &nbsp; &nbsp; &nbsp;# close unused parent stream<br>
 &nbsp; &nbsp;&amp;parent($c[$s], $s);<br>
 &nbsp; &nbsp;close $c[$s]; &nbsp; &nbsp; &nbsp; &nbsp;# close the stream coming back from the child<br>
 &nbsp; &nbsp;waitpid($pid[$s],0); # wait for child process to terminate<br>
 &nbsp;} else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # is the child<br>
 &nbsp; &nbsp;die "cannot fork: $!" unless defined $pid[$s]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# make sure pid == 0<br>
 &nbsp; &nbsp;close $c[$s]; &nbsp; &nbsp; &nbsp; &nbsp;# close the unused child stream<br>
 &nbsp; &nbsp;&amp;child($p[$s], $s);<br>
 &nbsp; &nbsp;close $p[$s]; &nbsp; &nbsp; &nbsp; &nbsp;# close stream that was talking to the parent<br>
 &nbsp; &nbsp;exit(0);<br>
 &nbsp;}<br>
}<br>
<br>
sub parent() { # read data coming from child process(es)<br>
 &nbsp;my $fh = shift;<br>
 &nbsp;my $s &nbsp;= shift;<br>
 &nbsp;print $fh "Parent Pid $$ is sending this\n";<br>&nbsp;
 while ($line = &lt;$fh&gt;) { # read data from child line by line until done<br>
 &nbsp; &nbsp;chomp($line);<br>
 &nbsp; &nbsp;print "Parent $s Pid $$ just read this: `$line'\n";<br>
 &nbsp;};<br>
}<br>
<br>
sub child() { # send data back to parent through filehandle<br>
 &nbsp;my $fh = shift;<br>
 &nbsp;print $fh "Child Pid $$ is sending this\n";<br>
 &nbsp;print $fh "Child Pid $$ sends some more\n";<br>&nbsp;chomp($line = &lt;$fh&gt;);<br>&nbsp;print "Child $s Pid $$ just read this: `$line'\n";<br>}<br>
<br>
# filehandles didn't behave well using array references and my ultimate solution<br>
# &nbsp;is going to create functions to perform tasks anyway so I just passed the<br>
# &nbsp;handles to subroutines<br>
<br>
-------------- cut ------------<br>bash-3.2$ ./test.pl <br>Parent 0 Pid 3784 just read this: `Child Pid 3800 is sending this'<br>Parent 0 Pid 3784 just read this: `Child Pid 3800 sends some more'<br>Child&nbsp; Pid 3800 just read this: `Parent Pid 3784 is sending this'<br>Child&nbsp; Pid 3808 just read this: `Parent Pid 3784 is sending this'<br>Parent 1 Pid 3784 just read this: `Child Pid 3808 is sending this'<br>Parent 1 Pid 3784 just read this: `Child Pid 3808 sends some more'<br>Parent 2 Pid 3784 just read this: `Child Pid 3288 is sending this'<br>Parent 2 Pid 3784 just read this: `Child Pid 3288 sends some more'<br>Child&nbsp; Pid 3288 just read this: `Parent Pid 3784 is sending this'<br>Parent 3 Pid 3784 just read this: `Child Pid 2956 is sending this'<br>Parent 3 Pid 3784 just read this: `Child Pid 2956 sends some more'<br>Child&nbsp; Pid 2956 just read this: `Parent Pid 3784 is sending this'<br>Child&nbsp; Pid 744 just read this: `Parent Pid 3784
 is sending this'<br>Parent 4 Pid 3784 just read this: `Child Pid 744 is sending this'<br>Parent 4 Pid 3784 just read this: `Child Pid 744 sends some more'<br><br></blockquote></div></div><br></div></div><br>



      <hr size=1><a href="http://us.rd.yahoo.com/evt=47519/*http://tc.deals.yahoo.com/tc/blockbuster/text1.com
">No Cost - Get a month of Blockbuster Total Access</a> now. Sweet deal for Yahoo! users and friends.</body></html>