Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Nov 2003 04:46:31 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        rmkml <rmkml@wanadoo.fr>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: question about _exit() function
Message-ID:  <3FC743A7.DC5461EA@mindspring.com>
References:  <Pine.LNX.4.58.0311272019050.16308@hp.mgn.net>

next in thread | previous in thread | raw e-mail | index | archive | help
rmkml wrote:
> is the _exit() function safe for a thread ?
> my program use vfork() and then execve in a thread context.
> The documentation mentions that the process has to call _exit() in case
> of failure.
> But this _exit() is really safe for the parent thread ?

The behaviour is undefined in the failure case, but only if you
have stablishd a pthread_atfork() handler that does anything in
the child.

In general, the more correct approach is to use posix_spawn(), but
FreeBSD doesn't support posix_spawn() (funny; this has come up now
twice in within 60 messages of each other, while ther was a very
long time when it was not pertinent at all...).

POSIX also sriously discourages the use of vfork(), and recommends
fork() instead, for threaded programs.

Note that the fork() only *ever* creates a single thread, so it
will only replicate the currently running thread and its address
space, rather than all currently running threads in the parent.

You said in another message that this is on 4.8.  I think that the
behaviour will not be quite what you expect, in that case, and that
it'll be better in -current, but might still not be what you expect
there, either (depends on what you are expecting).  See also:

http://www.opengroup.org/onlinepubs/007904975/functions/fork.html

-- Terry



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3FC743A7.DC5461EA>