From owner-freebsd-questions@FreeBSD.ORG Sat Oct 31 20:52:41 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 360921065676 for ; Sat, 31 Oct 2009 20:52:41 +0000 (UTC) (envelope-from psteele@maxiscale.com) Received: from server505.appriver.com (server505c.appriver.com [98.129.35.7]) by mx1.freebsd.org (Postfix) with ESMTP id 00AB78FC0A for ; Sat, 31 Oct 2009 20:52:40 +0000 (UTC) X-Policy: GLOBAL - maxiscale.com X-Primary: psteele@maxiscale.com X-Note: This Email was scanned by AppRiver SecureTide X-ALLOW: psteele@maxiscale.com ALLOWED X-Virus-Scan: V- X-Note: Spam Tests Failed: X-Country-Path: UNITED STATES->UNITED STATES->UNITED STATES X-Note-Sending-IP: 98.129.23.15 X-Note-Reverse-DNS: ht02.exg5.exghost.com X-Note-WHTLIST: psteele@maxiscale.com X-Note: User Rule Hits: X-Note: Global Rule Hits: 112 113 114 115 119 120 131 217 X-Note: Mail Class: ALLOWEDSENDER X-Note: Headers Injected Received: from [98.129.23.15] (HELO ht02.exg5.exghost.com) by server505.appriver.com (CommuniGate Pro SMTP 5.2.14) with ESMTPS id 15241268 for freebsd-questions@freebsd.org; Sat, 31 Oct 2009 15:52:40 -0500 Received: from mbx03.exg5.exghost.com ([169.254.1.128]) by ht02.exg5.exghost.com ([98.129.23.15]) with mapi; Sat, 31 Oct 2009 15:52:39 -0500 From: Peter Steele To: "freebsd-questions@freebsd.org" Date: Sat, 31 Oct 2009 15:52:37 -0500 Thread-Topic: system() call causes core dump Thread-Index: AcpaQrT779TEb05gRx2ytH1rxPJaigAKGE/A Message-ID: <7B9397B189EB6E46A5EE7B4C8A4BB7CB327D11A9@MBX03.exg5.exghost.com> References: <7B9397B189EB6E46A5EE7B4C8A4BB7CB327D117F@MBX03.exg5.exghost.com> <4AEC5E02.8040705@FreeBSD.org> In-Reply-To: <4AEC5E02.8040705@FreeBSD.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: RE: system() call causes core dump X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2009 20:52:41 -0000 >In UNIX it is not safe to perform arbitrary actions after forking a multi-= threaded process. You're basically expected to call exec soon after the fo= rk, although >you can do certain other work if you are very careful. >The reason for this is that after the fork, only one thread will be runnin= g in the child, and if that thread tries to acquire a lock or other formerl= y-shared resource >it may deadlock or crash, because the child process is no longer accessing= the same memory location as the threads in the parent process (it gets a s= eparate copy >of the address space at the time of fork, which may not be in a consistent= state from the point of view of the thread library). I am not calling fork explicitly. The thread I'm running in was created wit= h pthread_create(). The fork() in the stack trace in my original email is b= eing called by the system() function as it spawns off the process it is sup= posed want to run. Is there a safe way to call system() within a pthread? T= he app has several such threads doing various monitoring actions, some call= ing functions using system(), others invoking various C library routines. T= he parent process where these threads were spawned from is basically sleepi= ng, waking up only periodically to check for shutdown events.