develooper Front page | perl.perl5.porters | Postings from April 2012

[perl #40190] Solaris: BEGIN and exec, fork, system or open(|-,-|)

From:
Brian Fraser via RT
Date:
April 28, 2012 01:29
Subject:
[perl #40190] Solaris: BEGIN and exec, fork, system or open(|-,-|)
Message ID:
rt-3.6.HEAD-4610-1335542150-1734.40190-15-0@perl.org
On Sun Aug 20 12:02:54 2006, nicholas wrote:
> On Sun, Aug 20, 2006 at 07:47:34PM +0100, Nicholas Clark wrote:
> 
> > Most strange. truss shows that all the writes are in the parent:
> > 
> > 1609:   write(1, " P A R E N T :   C H E C".., 15)      = 15
> > 1609:   write(1, " P A R E N T :   C H E C".., 15)      = 15
> > 1609:   write(1, " P A R E N T :   I N I T".., 13)      = 13
> > 1609:   write(1, " P A R E N T :   I N I T".., 13)      = 13
> > 1609:   write(1, " P A R E N T :   t h a t".., 13)      = 13
> > 1609:   write(1, " 0\n", 2)                             = 2
> > 1609:   write(1, " P A R E N T :   t h a t".., 13)      = 13
> > 1609:   write(1, " 0\n", 2)                             = 2
> > 
> > So it's nothing as obvious as the child process failing to _exit()
at the
> > appropriate time.
> 
> B::Deparse shows that most of the program is duplicated. I think it's an
> interaction between fork() and the file position on the descriptor used to
> read the program. I can't remember exactly what the Solaris behaviour is,
> but there's something it does differently from most other operating
systems,
> I think at child exit, where it seeks file descriptors. Hopefully someone
> else can fill me in.
> 
> But what's happening is that the after the child exits, the underlying
Unix
> file descriptor that the interpreter is reading the program from has its
> position moved back, because that descriptor was shared with the child.
> The interpreter first reads all the buffered data, so you get the program
> compiled once. When the buffer is empty, it is refilled from the
underlying
> descriptor, which "should" have been at EOF, but now isn't. So parts of
> the program get read again.
> 
> I say "should" because I can't remember whose "fault" all this emergent
> behaviour is. It was discussed previously (in another context)
> 
> Nicholas Clark
> 

This is still present in 5.14.2 and blead.


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=40190



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