The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


fork - create a new process


#include <sys/types.h>
#include <unistd.h>

pid_t fork(void);


The fork() function creates a new process. The new process (child process) is an exact copy of the calling process (parent process) except as detailed below.

The inheritance of process characteristics not defined by this document is implementation-dependent. After fork(), both the parent and the child processes are capable of executing independently before either one terminates.

A process is created with a single thread. If a multi-threaded process calls fork(), the new process contains a replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources. Consequently, to avoid errors, the child process may only execute async-signal safe operations until such time as one of the exec functions is called. Fork handlers may be established by means of the pthread_atfork() function in order to maintain application invariants across fork() calls.


Upon successful completion, fork() returns 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, -1 is returned to the parent process, no child process is created, and errno is set to indicate the error.


The fork() function will fail if:
The system lacked the necessary resources to create another process, or the system-imposed limit on the total number of processes under execution system-wide or by a single user {CHILD_MAX} would be exceeded.

The fork() function may fail if:

Insufficient storage space is available.








alarm(), exec, fcntl(), semop(), signal(), times(), <sys/types.h>, <unistd.h>.


Derived from Issue 1 of the SVID.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]