fork

To create a new process in Unix, you must first make a copy of an existing process. That copy can continue to execute the code of the original process, or it can begin executing another program. The fork() system call performs the process copying:

pid_t fork (void);

fork() makes a copy of the running process, and it is one of the few functions that can return twice. In the original process, called the parent process, fork() returns the process ID of the new process. In the new process, called the child process, fork() returns zero. When an error occurs, there is no child process, and fork() returns -1 in the parent and sets errno.

As a copy of the parent process, the child inherits the parent process’ memory, open files, real and effective ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.