HELP: how to safely timeout a read on a filehandle?
Hey folks... this might be a "Perl internals" question for ya:
I have a Perl 4.036 application which communicates with a number
of databases via special database-specific child processes
it opens. These child processes issue queries to their underlying
database, and spit the results out to their stdout, which is
really a pipe back to the parent. Thus, accessing one looks like
this:
open(CHILD, "$childname |");
while ($line = <CHILD>) {
# do stuff
}
close(CHILD);
Now, like all children, THESE children might be ill-behaved, and
get hung up... so, I want to put a timeout on the read in the
second line, so that if the read times out, I can GRACEFULLY
close the filehandle, kill the child, and move on to the next child.
'Trouble is, I don't know how reentrant the filehandle routines
are... for example, can a SIGALRM signal handler safely close a
filehandle, or is there a risk of it being invoked whilst Perl
is in the middle of a data structure update? This, BTW, is the
#1 reason why poorly written signal handlers occasionally
crash C programs: programmers do stuff like attempting to use stdio
calls within the signal handler.
Any thoughts (or authoritative replies) would be appreciated.
PLEASE EMAIL TO ME; it may be awhile before I get back from
a trip, and I don't want your good responses to evaporate. :-)
Thanqs,
____ __
/ __/ _/ / / , / Hughes STX Corporation, NASA/Goddard Space Flight Cntr.
/___/_/ \ /\ /___
/_/ /_____/ http://www.*-*-*.com/ ~eryq/