FORK(2,L) AIX Technical Reference FORK(2,L) ------------------------------------------------------------------------------- fork, vfork PURPOSE Creates a new process. SYNTAX pid_t fork ( ) pid_t vfork ( ) DESCRIPTION The fork system call creates a new process. The new process (child process) is an exact copy of the calling process (parent process). The created child process inherits the following attributes from the parent process: o Environment o Close-on-exec flags (see "exec: execl, execv, execle, execve, execlp, execvp") o Signal handling settings (that is, SIG_DFL, SIG_IGN, function address) o Set-user-ID mode bit o Set-group-ID mode bit o Profiling on/off status o Nice value (see "getpriority, setpriority, nice") o All attached shared libraries (see shlib command in AIX Operating System Commands Reference) o Process group ID o Session ID o TTY group ID (see "exit, _exit" and "sigaction, sigvec, signal") o Current directory o Root directory o File mode creation mask (see "umask") o System resource limits (see "ulimit") o Attached shared memory segments (see "shmat") o alias pathname (see "getlocal, setlocal") o xvers string (see "getxvers, setxvers"). If the Transparent Computing Facility is installed, the following attributes are also inherited by the child process: o Execution site (see "rfork" to change execution sites) o Site path (see "getspath, setspath") o Execution site permissions (see "getxperm, setxperm") o setxuid bits (see "setxuid"). Processed November 7, 1990 FORK(2,L) 1 FORK(2,L) AIX Technical Reference FORK(2,L) The child process differs from the parent process in the following ways: o The child process has a unique process ID. The child process ID also does not match any active process group ID. o The child process has as its parent process ID the process ID of the parent process. o The child process has its own copy of the parent's file descriptors. However, each of the child process's file descriptors shares a common file pointer with the corresponding file descriptor of the parent process. o All semadj values are cleared. (For information about semadj values, see "semop.") o Process locks, text locks and data locks are not inherited by the child. (For information about locks, see "plock.") o The child process's trace flag (see the discussion of request 0 of "ptrace") is false regardless of the value of the parent process's trace flag. o The child process's utime, stime, cutime, and cstime are set to 0. (See "times.") o Any pending alarms are cleared in the child. (See "alarm.") If the Transparent Computing Facility is installed, the fork system call only creates a new process on the local site (see "rfork"). COMPATIBILITY NOTE The vfork system call is supported as a compatibility interface for older BSD programs, and can be used by compiling with Berkeley Compatibility Library (libbsd.a). Its function is superceded by fork. The 4.3BSD documentation warned that programs should not rely upon the unusual memory sharing semantics of vfork, since eventually "proper system sharing mechanisms" would be implemented. Accordingly, in AIX, fork and vfork have identical behavior. RETURN VALUE Upon successful completion, fork returns a value of 0 to the child process and returns the process ID of the child process to the parent process. If fork fails, a value of -1 is returned to the parent process, no child process is created, and errno is set to indicate the error. ERROR CONDITIONS The fork system call fails if one or more of the following are true: Processed November 7, 1990 FORK(2,L) 2 FORK(2,L) AIX Technical Reference FORK(2,L) EAGAIN The system-imposed limit on the total number of processes executing would be exceeded. EAGAIN The system-imposed limit on the total number of processes executing for a single user would be exceeded. ENOMEM There is not enough space left for this process. RELATED INFORMATION In this book: "exec: execl, execv, execle, execve, execlp, execvp," "exit, _exit," "getpriority, setpriority, nice," "getspath, setspath," "getxvers, setxvers," "getxperm, setxperm," "plock," "ptrace," "rfork," "semop," "setxuid," "shmat," "sigaction, sigvec, signal," "times," "ulimit," "umask," and "wait, waitpid." The shlib2 command in AIX Operating System Commands Reference. Processed November 7, 1990 FORK(2,L) 3