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

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

Thread Next
From:
Ilya Zakharevich
Date:
October 2, 2005 05:12
Subject:
[BUG] fork() does not preserve position in file (SeflLoader etc) [perl #37119]
Message ID:
20051001213319.GA14186@math.berkeley.edu
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
 http://groups.google.com/group/comp.lang.perl.modules/msg/ffafaf280e1423d7
  ]

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...).

Yours,
Ilya

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

  perl -dwe0

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

  fork

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


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