From owner-freebsd-hackers@FreeBSD.ORG Fri Nov 28 06:51:44 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D7AAB16A4CE for ; Fri, 28 Nov 2003 06:51:44 -0800 (PST) Received: from mwinf0801.wanadoo.fr (smtp8.wanadoo.fr [193.252.22.23]) by mx1.FreeBSD.org (Postfix) with ESMTP id B79C043FA3 for ; Fri, 28 Nov 2003 06:51:43 -0800 (PST) (envelope-from rmkml@wanadoo.fr) Received: from [192.168.1.2] (AVelizy-109-1-2-209.w80-14.abo.wanadoo.fr [80.14.9.209]) by mwinf0801.wanadoo.fr (SMTP Server) with ESMTP id 35FF018000B0; Fri, 28 Nov 2003 15:51:42 +0100 (CET) Date: Fri, 28 Nov 2003 15:48:46 +0100 (CET) From: rmkml X-X-Sender: rmkml@hp.mgn.net To: Terry Lambert In-Reply-To: <3FC743A7.DC5461EA@mindspring.com> Message-ID: References: <3FC743A7.DC5461EA@mindspring.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-hackers@freebsd.org Subject: Re: question about _exit() function X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2003 14:51:45 -0000 Thanks a lot for the answer. I will change vfork() with fork(). An another question: in the man page of vfork() it is mentionned that the fork() function has to use _exit(0) too when something wrong with the execve() happens! but in a thread context of my program, the use of _exit() may not be best practice. Is the child a real process or because of the thread context a part of the parent process, so a new thread. In this case a pthread_exit() may be a better solution. Is that point a view complety wrong ? Currently, is some indeterminate case, a part of my program freeze just after the vfork(). So, I try to understand what may cause the calling thread of vfork() to freeze ... Thanks a lot! On Fri, 28 Nov 2003, Terry Lambert wrote: > Date: Fri, 28 Nov 2003 04:46:31 -0800 > From: Terry Lambert > To: rmkml > Cc: freebsd-hackers@freebsd.org > Subject: Re: question about _exit() function > > 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 >