bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in exit()?


From: Michael Kerrisk
Subject: Re: Bug in exit()?
Date: Tue, 24 Apr 2001 21:25:43 +0200

Gidday Wolfram,

Thanks for your note.

> > In the supplied program, the vfork()ed child runs in its parent's
> > address
> > space (test on SuSE 6.4, Kernel 2.2.14, glibc 2.2.3), and so its call to
> > exit should close the parent's stdout buffer, and cause the printf() in
> > the parent to fail.  Instead the printf() succeeds.  Uncommenting the
> > fclose() in the child achieves the effect that should be achieved just by
> > the child calling exit().
> 
> Please take a look at
> 
> http://www.UNIX-systems.org/onlinepubs/007908799/xsh/vfork.html
> 
> I conclude from it that calling exit() in the child is not allowed,
> only _exit() is.

I see your idea, however the standard merely says that calling anything other 
than exec/_exit is undefined, not that it is disallowed.  In any case my report 
is not about vfork() - that is rather the way I discovered the problem with 
exit(): the standards explicitly say that exit() should close stdio file 
streams.  Traditional Unix (BSD) behaviour in this circumstance, is that the 
behaviour I have described should occur for the example program I have 
provided(see for example Stevens "Avanced Programming Unix Environment", 
program 8.2, P 194, and exercise 8.1, p235. 

> Also:
> 
> >      default:   /* Parent is blocked until child exits */
> 
> How do you get that idea?  I'm pretty sure parent and child can
> execute concurrently.

Traditional BSD semantics are that they cannot - again, see Stevens p193ff or 
the BSD vfork man page - here's the FreeBSD vfork description:

     Vfork() can be used to create new processes without fully copying the ad-
     dress space of the old process, which is horrendously inefficient in a
     paged environment.  It is useful when the purpose of fork(2) would have
     been to create a new system context for an execve(2).  Vfork() differs
     from fork(2) in that the child borrows the parent's memory and thread of
     control until a call to execve(2) or an exit (either by a call to _ex-
     it(2) or abnormally).  The parent process is suspended while the child is
     using its resources.

Only those Unices which quickly hacked a vfork() as a simple call to fork() do 
allow the parent to execute before the child exits or execs.

Cheers

Michael
__________________________________________
Michael Kerrisk
mailto: address@hidden

This message was written using Pegasus mail.
http://www.pegasus.usa.com/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]