perl Write filehandle blocks.



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

  • Re: Got stuck with redirecting to less
    ... I have originally tried "your code with my corrections" on ... > ever in the meantime the child accidentally exits, the parent receives ... > pipe when it exits, so child receives the EOF on the other side. ...
    (comp.unix.programmer)
  • Re: using pthreads with fork() in linux
    ... the child program performs some action and exits. ... the parent doesn't success to see that his child exited. ... The cast is unnecessary and dangerous here. ...
    (comp.os.linux.development.apps)
  • Re: Got stuck with redirecting to less
    ... > It is needless only if the parent exits. ... > If the parent does wait (and it must, or else less will get EIO ... processes "linked" with a pipe. ... so child receives the EOF on the other side. ...
    (comp.unix.programmer)
  • Re: using pthreads with fork() in linux
    ... the child program performs some action and exits. ... What I see is that the pthread manager process becomes a zombee, ... the parent doesn't success to see that his child exited. ...
    (comp.programming.threads)
  • Unix Programming FAQ (v1.37)
    ... Why use _exit rather than exit in the child branch of a fork? ... Why doesn't my process get SIGHUP when its parent dies? ... How do I create a named pipe? ... How do I compare strings using regular expressions? ...
    (comp.unix.programmer)