Re: question about _exit() function

From: Terry Lambert (tlambert2_at_mindspring.com)
Date: 11/28/03

  • Next message: rmkml: "Re: question about _exit() function"
    Date: Fri, 28 Nov 2003 04:46:31 -0800
    To: rmkml <rmkml@wanadoo.fr>
    
    

    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
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"


  • Next message: rmkml: "Re: question about _exit() function"

    Relevant Pages

    • Re: question about _exit() function
      ... I will change vfork() with fork. ... but in a thread context of my program, the use of _exitmay not be ... > will only replicate the currently running thread and its address ...
      (freebsd-hackers)
    • Re: question about _exit() function
      ... I will change vfork() with fork. ... operate in the context of the child. ... of using various libraries or shared objects. ...
      (freebsd-hackers)
    • Re: RFC: implement daemon() in the kernel
      ... being able to use real shells such as bash and thereby being able to use real shell scripts. ... Even if the cost of transferring memory contents was cheap, you'd annoy the memory management subsystem unless you did a lot of weird tricks to avoid allocating from a large block. ... I did not mean to suggest that vfork() should go away or that shells that make use of it go away. ... It is just that making fork() work has a lot of value. ...
      (Linux-Kernel)
    • how to "wrap" vfork?
      ... My program needs to keep track of processes, so it has a little code to ... wrap the fork() system call. ... to be - so I figured I'd better catch vfork() uses as well. ... Unfortunately it turns out to be impossible to put a wrapper function ...
      (comp.unix.solaris)
    • how to "wrap" vfork?
      ... My program needs to keep track of processes, so it has a little code to ... wrap the fork() system call. ... to be - so I figured I'd better catch vfork() uses as well. ... Unfortunately it turns out to be impossible to put a wrapper function ...
      (comp.unix.programmer)