Re: perl Write filehandle blocks.



if i run the code like "cat passwd|perl head.pl", if size of passwd
file is less it works fine, if it is more than 4k it hangs.


On Apr 29, 1:11 pm, kira...@xxxxxxxxxxx wrote:
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);
}


.



Relevant Pages

  • PROBLEM: threaded process stuck on 2.4.2[12]
    ... Download OpenProducer ... For me the application hangs, until I hit CTRL+Z and then do ... Process 5191 attached (waiting for parent) ... I didn't try to reproduce this problem on 2.5/6 kernels, ...
    (Linux-Kernel)
  • Re: OT: Poll - Most Disturbing Book Youve Read
    ... Whereas a parent of someone who has shot up a campus... ... of a series of letters to the "estranged husband", ... story about a mother who blames herself,, a father who can see no ... The writing was good but I ...
    (rec.arts.mystery)
  • Re: Race condition in debugger?
    ... What happens is that the debugger hangs at some ... that there's no lock protecting that the conditions in the ... >hold the parent lock across the bulk of kern_wait, ... the race has just occurred. ...
    (freebsd-current)
  • Re: OT: Poll - Most Disturbing Book Youve Read
    ... Whereas a parent of someone who has shot up a campus... ... kids who shot up Columbine aren't talking either, ... of a series of letters to the "estranged husband", ... The writing was good but I ...
    (rec.arts.mystery)
  • Re: FBoFW 5/8/06
    ... knowing and all seeing...she's just a parent who probably had a kid with an ... I'm not writing a strip where the character dealing ... people care waay too much about the sex lives of my characters..." ...
    (rec.arts.comics.strips)