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:
LAUN Wolfgang
Date:
May 28, 2004 12:18
Subject:
Re: [perl #29883] Closing file seems to cause a seek operation
Message ID:
DF27CDCBD2581D4B88431901094E4B4D02B0C73D@attmsx1.aut.alcatel.at
Hello Andy,

On 26 May 2004 14:19:57 -0000 Lauder, Andy wrote:
> Why does perl perform a seek before the close of a file?
> 
> I'm using Perl 5.8.3 on Solaris 8 and I'm seeing a problem with the 'close'
> function (either explicitly called by using the 'close' perl function or
> implicitly called by exiting a child subroutine with the file left open).
> 
> 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. 

As far as Perl is concerned: it is strange that this insertion removes the problem:  

        } elsif (defined $child_pid){
+                my $fd = fileno( FIN );
+                open( XXX, "<&=$fd" );
                 sleep 1;

Kind regards
Wolfgang Laun


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