develooper Front page | perl.perl5.porters | Postings from May 2004

Re: [perl #29883] Closing file seems to cause a seek operation

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
May 28, 2004 13:55
Subject:
Re: [perl #29883] Closing file seems to cause a seek operation
Message ID:
20040528205513.GW1147@plum.flirble.org
On Fri, May 28, 2004 at 11:26:51AM +0200, LAUN Wolfgang wrote:
> Hello Andy,
> 
> On 26 May 2004 14:19:57 -0000 Lauder, Andy wrote:

> > If I use the following program:
> >
> > open FIN, "test.input";
> >
> > $transaction_no = 0;
> > while($line = <FIN>){
> >         $transaction_no++;
> > 
> >        if ($child_pid = fork){
> >                 print "$$ processing line :$line: :$transaction_no: :".tell(FIN).":\n";
> > 
> >                 waitpid $child_pid,0;
> >        } elsif (defined $child_pid){
> >                 sleep 1;
> >                 exit 0;
> >        }
> > }
> >
> > In other words, the program never ends but loops continuously through the
> > file as though it has missed the EOF.
> 
> I get the same on SunOS 5.8 with perl 5.8.0.
> 
> An equivalent C program (fopen, fgets, ftell) shows the same behaviour, and
> also does on SunOS 5.9. So it is definitely not a Perl problem.
> 
> According to a colleague who has looked into this, it is not clear whether it is in the standard io library or buried deep in fork handling. It should be reported to Sun, and we'd like to cooperate on this with you. 

I had this hunch that it's because you're using exit() (rather than _exit()),
and I'd guess that exit is calling fflush(), and that you're hitting the
bug in Solaris that fflush() clobbers input streams.

(ie something non-conformant with C89. Yes. C EIGHTY nine. Not C99.
Everyone expecting universal C99 conformance any time soon will be
disappointed)

IIRC this is fixed now, but I can still reproduce your loop on a Solaris 10
machine. However, if I change exit() to POSIX::_exit() the problem goes away.

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About