On Tuesday 09 May 2006 8:13 am, Matthias Hopf wrote:
Be very careful of using fork(2) from threads. To quote from Dave Butenhof, "Avoid using forkin a threaded program (if you can) unless you intend to exec a new program immediately". Page 197 "Programming with POSIX Threads".
Why that? Yes, you have to be carefull about open file descriptors and memory maps (and other IPC stuff), but it should work. Apache is successfully using a mixture of threads and processes.
Agreed that it should work, and does. But, you must be aware of what you get in a child process and what you do not get. For instance, when you fork(2) from a thread, the new process inherits the one thread and its state, but not any of the other threads. You also must be very careful of signals.