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

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

Thread Previous
From:
Lauder, Andy
Date:
May 26, 2004 07:24
Subject:
[perl #29883] Closing file seems to cause a seek operation
Message ID:
rt-3.0.9-29883-88224.11.4067664319764@perl.org
# New Ticket Created by  "Lauder, Andy" 
# Please include the string:  [perl #29883]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=29883 >


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;
        }
}


 together with the following input file (test.input):


LINE 1
LINE 2
LINE 3
LINE 4
LINE 5


and then run the program, I get:


14097 processing line :LINE 1
: :1: :7:
14097 processing line :LINE 2
: :2: :-14:
14097 processing line :LINE 3
: :3: :-7:
14097 processing line :LINE 4
: :4: :0:
14097 processing line :LINE 5
: :5: :0:
14097 processing line :LINE 1
: :6: :7:
14097 processing line :LINE 2
: :7: :-14:
14097 processing line :LINE 3
: :8: :-7:
14097 processing line :LINE 4
: :9: :0:
14097 processing line :LINE 5
: :10: :0:
14097 processing line :LINE 1
: :11: :7:
14097 processing line :LINE 2
: :12: :-14:

etc
etc
etc



In other words, the program never ends but loops continuously through the
file as though it has missed the EOF.  Note that the field showing the
result of the 'tell' function seems to be counting down, goes through 0 and
repeats again.

Using the UNIX command 'truss' reveals that the child process is using a
'seek' command just before the file is closed which seems to be causing the
parent to miss the EOF marker.

Note that if the file is explicitly closed in the child subroutine, the same
problem occurs.

Why does perl perform a seek before the close?

Is this a bug?


Regards,

Andy Lauder

This e-mail is intended only for the above addressee. It may contain
privileged information. If you are not the addressee you must not copy,
distribute, disclose or use any of the information in it. If you have
received it in error please delete it and immediately notify the sender.
Security Notice: all e-mail, sent to or from this address, may be
accessed by someone other than the recipient, for system management and
security reasons. This access is controlled under Regulation of
Investigatory Powers Act 2000, Lawful Business Practises.


Thread Previous


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