fork() Gotchas

While Unix file descriptors are inherited across fork(), most Mach ports are not. Cocoa relies on Mach ports for much of its private interprocess communication, including communication with the window server. Expect problems if you try to use Cocoa after a fork().

When you are using threads (which Cocoa and Core Foundation programs use implicitly), only the thread that calls fork() is running in the child. Unfortunately, all of the other thread stuff (mutexes and other data structures) still exists, and data structures that are protected by mutexes are potentially still in an indeterminate state, which can lead to total mayhem.

If you are using threads (or if a framework or library is using them on your behalf), the only safe ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.