I have a situation where I need to spawn a helper process from within a very large, multithreaded application, which I do not have complete control over.
Right now I\'m
Calling fork
should be safe if you limit yourself to "raw" system calls (syscall(SYS_fork)
, syscalll(SYS_execve, ...)
, etc.). Call into any glibc routine, and you'll be in a lot of trouble.
Calling vfork
is not at all what you want: only the thread that called vfork
is suspended, and other threads will continue to run (and in the same address space as the vforked child). This is very likely to complicate your life.
Calling clone
directly is possible, but exceedingly tricky. We have an implementation that allows for safe forking of child processes from multithreaded apps (unfortunately not open source). That code is very tricky, and surprisingly long.