Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 31 Oct 2009 15:52:37 -0500
From:      Peter Steele <psteele@maxiscale.com>
To:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   RE: system() call causes core dump
Message-ID:  <7B9397B189EB6E46A5EE7B4C8A4BB7CB327D11A9@MBX03.exg5.exghost.com>
In-Reply-To: <4AEC5E02.8040705@FreeBSD.org>
References:  <7B9397B189EB6E46A5EE7B4C8A4BB7CB327D117F@MBX03.exg5.exghost.com> <4AEC5E02.8040705@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
>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.




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