K
kiranmn
hi,
First parent do a fork, parent waits for child to finish , child
runs a command "head" and exits. After waiting parent sleep fror 1
hours and continue doing same thing. when i write a file to t "open2",
write filehandle, it just hangs there, what is the reason.
Following is my code. It stops at " now writing to write fd
". Please help me.
Thanking you,
regards,
kiran
========================================
#!/usr/bin/perl -I../lib
#use strict;
use Carp qw(verbose);
use IPC::Open2;
use Symbol;
my $WTR;
my $RDR;
while(1)
{
if($kid=fork)
{
waitpid($kid,0);
}
else
{
while(<STDIN>)
{
$ref->{"mail"}.=$_;
}
$WTR = gensym(); # get a reference to a typeglob
$RDR = gensym(); # and another one
$pid=open2($RDR, $WTR, "/usr/bin/head ");
print "now writing to write fd\n";
$oo=select $WTR;
$|=1;
select $oo;
print $WTR "$ref->{\"mail\"}";
print "closing writing fd\n";
close($WTR);
print "going to reader\n";
while(<$RDR>)
{
print "$_";
}
print "comming out of while reader\n";
close($RDR);
exit;
}
sleep (3600);
}
First parent do a fork, parent waits for child to finish , child
runs a command "head" and exits. After waiting parent sleep fror 1
hours and continue doing same thing. when i write a file to t "open2",
write filehandle, it just hangs there, what is the reason.
Following is my code. It stops at " now writing to write fd
". Please help me.
Thanking you,
regards,
kiran
========================================
#!/usr/bin/perl -I../lib
#use strict;
use Carp qw(verbose);
use IPC::Open2;
use Symbol;
my $WTR;
my $RDR;
while(1)
{
if($kid=fork)
{
waitpid($kid,0);
}
else
{
while(<STDIN>)
{
$ref->{"mail"}.=$_;
}
$WTR = gensym(); # get a reference to a typeglob
$RDR = gensym(); # and another one
$pid=open2($RDR, $WTR, "/usr/bin/head ");
print "now writing to write fd\n";
$oo=select $WTR;
$|=1;
select $oo;
print $WTR "$ref->{\"mail\"}";
print "closing writing fd\n";
close($WTR);
print "going to reader\n";
while(<$RDR>)
{
print "$_";
}
print "comming out of while reader\n";
close($RDR);
exit;
}
sleep (3600);
}