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 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.