FORK(2) SysV FORK(2)
NAME
fork - create a new process
SYNOPSIS
#include <sys/types.h>
pid_t fork ( void );
DESCRIPTION
The fork function creates a new process (child process) that is identical
to the calling process (parent process).
The child process inherits the following attributes from the parent
process:
+ Environment
+ Close-on-exec flags
+ Signal handling settings
+ Set user ID mode bit
+ Set group ID mode bit
+ Profiling on/off status
+ Nice value
+ All attached shared libraries
+ Process group ID
+ tty group ID
+ Current directory
+ Root directory
+ File mode creation mask
+ File size limit
The child process differs from the parent process in the following ways:
+ The child process has a unique process ID and does not match any
active process group ID.
+ The parent process ID of the child process matches the process ID of
the parent.
+ The child process has its own copy of the parent process's file
descriptors. However, each of the child's file descriptors shares a
common file pointer with the corresponding file descriptor of the
parent process.
+ All semadj values are cleared.
+ Process locks, text locks, and data locks are not inherited by the
child process.
+ The child process's utime, stime(), cutime(), and cstime are set to
0 (zero).
+ Any pending alarms are cleared in the child process.
NOTES
Programs which open streams using Domain/OS calls and then fork() may not
to work as expected. From the mbx calls, for instance, server handles
aren't reference counted. Similar incompatibilities with fork() exist
among the gpr and gpio Domain/OS calls. (Streams opened with the ios
Domain/OS system calls are compatible with fork().)
DIAGNOSTICS
Upon successful completion, the fork function returns a value of 0 (zero)
to the child process and returns the process ID of the child process to
the parent process. If the fork function fails, a value of -1 is
returned to the parent process, no child process is created, and errno is
set to indicate the error.
ERRORS
The fork function fails if
[EAGAIN] The system-imposed limit on the total number of processes
executing for a single user would be exceeded, or the system-
imposed limit on the total number of processes under execution
would be exceeded.
[EAGAIN] Total amount of system memory available when reading via raw
I/O is temporarily insufficient.
SEE ALSO
exec(2), exit(2), getrusage(2), nice(2), plock(2), ptrace(2), raise(3C),
semop(2), shmop(2), sigaction(2), signal(2), times(2), ulimit(2),
umask(2), wait(2)