Inside the child process, only one thread exists. It is made from a copy of the
thread that called fork in the parent. If the threads in the parent process hold
any……
[/Quote]
尽信书不如无书
各个平台fork的语义有细小的差别,APUE写作的年代相对来说比较早,有情况可能照不到现在的情况
有时间的话可以参考一下ACE在进程派生这块的源码,就知道各个平台有哪些不同了
Inside the child process, only one thread exists. It is made from a copy of the
thread that called fork in the parent. If the threads in the p……
[/Quote]
Inside the child process, only one thread exists. It is made from a copy of the
thread that called fork in the parent. If the threads in the parent process hold
any locks, the locks will also be held in the child process. The problem is that
the child process doesn't contain copies of the threads holding the locks, so
there is no way for the child to know which locks are held and need to be unlocked.
A process is created with a single thread. If a multi-threaded process calls fork(), the new process contains 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. Fork handlers may be established by means of the pthread_atfork() function in order to maintain application invariants across fork() calls.