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

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

From:
Alan Burlison
Date:
May 28, 2004 15:25
Subject:
Re: [perl #29883] Closing file seems to cause a seek operation
Message ID:
40B7BC37.8050602@sun.com
Nicholas Clark wrote:

 > I had this hunch that it's because you're using exit() (rather than 
_exit()),
 > and I'd guess that exit is calling fflush(), and that you're hitting the
 > bug in Solaris that fflush() clobbers input streams.

That particular bug was fixed in Solaris 8, AFAIK, this is something 
different.

 > (ie something non-conformant with C89. Yes. C EIGHTY nine. Not C99.
 > Everyone expecting universal C99 conformance any time soon will be
 > disappointed)

The behaviour exhibited is required by SVID.  It's doing what it is 
supposed to
do.

 > IIRC this is fixed now, but I can still reproduce your loop on a 
Solaris 10
 > machine. However, if I change exit() to POSIX::_exit() the problem 
goes away.

As the fork() manpage says:

      An application should call _exit() rather than exit(3C)  if
      it  cannot execve(), since exit() will flush and close stan-
      dard I/O channels and thereby corrupt the  parent  process's
      standard I/O data structures.

Big rule:  Don't use exit() after fork(), use _exit().

--
Alan Burlison
--




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