Checking if fork () is safe

fork () behavior is undefined if there are multiple threads in a process. How can I verify that there is only one thread (mainly on linux, but windows, darwin are also of interest)?

+3
source share
2 answers

On Linux, fork () behavior is not undefined in a multi-threaded process, but it does things that are usually not very useful.

Rather, if you fork () and do not immediately call exec (), you risk leaking unspecified resources, possibly including locks that could cause a deadlock.

, Linux ( procfs), . , , .

+2

. pthreads pthread_is_multithreaded_np(), fork() pthreads, . .

, . , fork() ( fork/execv).

, fork(), , .

pthread_atfork(...), , fork().

+2

Source: https://habr.com/ru/post/1778790/


All Articles