The fork(2) Function
The synopsis for the fork(2) system call is as follows:
#include <sys/types.h> #include <unistd.h> pid_t fork(void);
There are no arguments to the fork(2) system call. When the call is successful, the parent process receives the process ID of the child process that was created. The child process, however, receives the return value 0 instead. The child process is always able to obtain the parent process ID by calling upon getppid(2).
The caller should always anticipate errors, however. The fork(2) call returns the value (pid_t)(-1) if the function fails. The value of errno will hold the reason for the error. Possible reasons for failure include EAGAIN when the system-imposed limit for the number of processes has been exceeded. ...
Get Advanced UNIX Programming 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.