| José Pedro Silva Pinto 2005-03-24, 8:56 am |
| Hi,
I want make a bi-directional communication between two processes, using =
pipes.
To make it possible, I create 2 pipes, on for on way ( =
pipe(LEI_1,WRITE_1) ) an another to opposite way =
(pipe(READ_2,WRITE_2);).
When I run my program, the process stops on PROCESS 2 END, if I comment =
the line $buf =3D <LEI_1>;, it runs well
Code (run well )
#!/opt/perl5/bin/perl5.6.1
$SIG{'CHLD'} =3D 'IGNORE';
pipe(LEI_1,WRITE_1);
pipe(READ_2,WRITE_2);
if ($pid =3D fork)
{
close LEI_1;
close WRITE_2;
print "PROCESS 1 \n";
printf WRITE_1 "Hello father:";
$pai =3D <READ_2>;
print "Message from father: $pai \n ";
sleep 2;
print "PROCESS 1 END \n";
exit(0);
}
if ($pid =3D fork)
{
print "PROCESS 2 \n";
sleep 1;
print "PROCESS 2 END \n";
exit(0);
}
close WRITE_1;
close READ_2;
#$buf =3D <LEI_1>;=20
print "message from son : $buf \n";
printf WRITE_2 "Hello Son";
exit(0);
****************************************
******************************
OUTPUT:
PROCESS 1=20
PROCESS 2=20
message from son : =20
PROCESS 2 END=20
Message from father: Hello Son=20
PROCESS 1 END=20
****************************************
******************************
CODE (NOT RUN) (With $buf =3D <LEI_1>; uncommented)
#!/opt/perl5/bin/perl5.6.1
$SIG{'CHLD'} =3D 'IGNORE';
pipe(LEI_1,WRITE_1);
pipe(READ_2,WRITE_2);
if ($pid =3D fork)
{
close LEI_1;
close WRITE_2;
print "PROCESS 1 \n";
printf WRITE_1 "Hello father:";
$pai =3D <READ_2>;
print "Message from father: $pai \n ";
sleep 2;
print "PROCESS 1 END \n";
exit(0);
}
if ($pid =3D fork)
{
print "PROCESS 2 \n";
sleep 1;
print "PROCESS 2 END \n";
exit(0);
}
close WRITE_1;
close READ_2;
#$buf =3D <LEI_1>;=20
print "message from son : $buf \n";
printf WRITE_2 "Hello Son";
exit(0);
****************************************
************
OUTPUT:
PROCESS 1=20
PROCESS 2=20
PROCESS 2 END
****************************************
************
So, it's very strange, so I can not have two pipes?, what's the problem.
Thanks
|