Tech Support > Operating Systems > Linux / Variants > perl hangs when piping
perl hangs when piping
Posted by funtoosh on February 27th, 2004


Hi

am using Perl 5.8.0 on RH-9 box (kernel 2.4.20.x)

I have this command

/home/me/myProgram |perl myPscript.pl >/tmp/log-file &
which runs fine when run from command prompt.
Purpose of myPscript.pl is to detect EOF condition and exit on it.
So, when /home/me/myProgram is killed, myPscript.pl detects it and
exits gracefully.

But problem starts when
I run the above command as :

rsh anotherBox "/home/me/myOtherProgram |perl myPscript.pl
( Here myOtherProgram is a threaded (POSIX) program and it creates 2
threads when running )


then I logon to anotherBox and manually kill myProgram's main thread (
When main dies, child threads also dies ) so that EOF is send to my
perl script.

But I noticed that the moment I kill main thread, perl starts taking
99.9 of cpu
and doesnt die. It is looking for some resource but what ?

any clue ?

perl script :
-----------------------------------------
while (<>) {
push @buffer;
}
print @buffer;
-------------------------------------------------

Posted by Sybren Stuvel on February 27th, 2004


["Followup-To:" header set to comp.os.linux.]
funtoosh enlightened us with:
AFAIK it doesn't send EOF. It sends a SIGPIPE signal. Try handling that
in your perl script, and just call die() there.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?


Similar Posts