fork semantics
Terry Lambert
tlambert2 at mindspring.com
Fri Jun 13 09:29:44 PDT 2003
Petri Helenius wrote:
> Could somebody point me how fork is wrapped/implemented with libkse ?
http://www.opengroup.org/onlinepubs/007904975/nfindex.html
> Do all threads get duplicated and which would be the recommended way to
> spin something off hanging on a pipe talking to one of the threads already in
> existence?
"A process shall be created with a single thread. If a
multi-threaded process calls fork(), the new process shall
contain a replica of the calling thread and its entire
address space, possibly including the states of mutexes
and other resources. Consequently, to avoid errors, the
child process may only execute async-signal-safe
operations until such time as one of the exec functions
is called. [THR] Fork handlers may be established by
means of the pthread_atfork() function in order to
maintain application invariants across fork() calls.
When the application calls fork() from a signal handler
and any of the fork handlers registered by pthread_atfork()
calls a function that is not asynch-signal-safe, the
behavior is undefined."
-- Terry
More information about the freebsd-threads
mailing list