develooper Front page | perl.perl5.porters | Postings from October 2005

[BUG] fork() does not preserve position in file (SeflLoader etc) [perl #37119]

Thread Next
Ilya Zakharevich
October 2, 2005 05:12
[BUG] fork() does not preserve position in file (SeflLoader etc) [perl #37119]
Message ID:
I do not think this effect is documented anywhere:

  perl -wle 'open F, q(<), shift or die; defined fork or die;
	     open O, q(>x).$$; print O $_ while <F>' .article

Two files x$$ are created (one per process).  One of the them is
empty.  (Both on Solaris and OS/2; but this may be system-dependent.)

Obviously, forked process share the same position in file.  One of the
culprits is the DATA file handle (see bug [perl #37119]): SelfLoader
will work in only one of the processes (unless it already read the
<DATA> section).

  [Sounds familiar; see

It should be considered a bug in implementation of <DATA> handle.  It
must tell() initially and after each read, and seek() back before each
read if any fork() was performed (drat, there is still a race
condition; maybe it should dup() first...).


P.S.  How to reproduce:  e.g., start

  perl -dwe0

in an XTerm (with ReadLine::Perl), then type


Now type something to the command line in one terminal and press
BackSpace key.  After this BackSpace won't work in other terminal.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About