Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fork(2) — HP-UX 7.01

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

acct(2)

chroot(2)

exec(2)

exit(2)

fcntl(2)

getgroups(2)

lockf(2)

nice(2)

plock(2)

profil(2)

ptrace(2)

rtprio(2)

semop(2)

setuid(2)

setpgrp(2)

shmop(2)

signal(5)

times(2)

ulimit(2)

umask(2)

vfork(2)

wait(2)

fclose(3S)

stdio(3S)

acct(4)

FORK(2)

NAME

fork − create a new process

SYNOPSIS

#include <sys/types.h>
pid_t fork ()

DESCRIPTION

Fork causes the creation of a new process.  The new process (child process) is an exact copy of the calling process (parent process).  This means that the child process inherits the following attributes from the parent process:

real, effective, and saved user ID

real, effective, and saved group ID

list of supplementary group IDs (see getgroups(2))

process group ID

environment

file descriptors

close-on-exec flags (see exec(2))

signal handling settings (SIG_DFL, SIG_IGN, address)

signal mask (see sigvector(2))

profiling on/off status (see profil(2))

command name in the accounting record (see acct(4))

nice value (see nice(2))

all attached shared memory segments (see shmop(2))

current working directory

root directory (see chroot(2))

file mode creation mask (see umask(2))

file size limit (see ulimit(2))

real-time priority (see rtprio(2))

Each of the child’s file descriptors shares a common open file description with the corresponding file descriptor of the parent.  This implies that changes to the file offset, file access mode, and file status flags of file descriptors in the parent also affect those in the child, and vice-versa. 

The child process differs from the parent process in the following ways:

The child process has a unique process ID.  The child process ID also does not match any active process group ID. 

The child process has a different parent process ID (which is the process ID of the parent process). 

The set of signals pending for the child process is initialized to the empty set. 

The trace flag (see ptrace(2) PT_SETTRC request) is cleared in the child process.

The AFORK flag in the ac_flags component of the accounting record is set in the child process. 

Process locks, text locks, and data locks are not inherited by the child (see plock(2)).

All semadj values are cleared (see semop(2)).

The child process’s values of tms_utime, tms_stime, tms_cutime, and tms_cstime are set to zero; see times(2).

The time left until an alarm clock signal is reset to 0 (clearing any pending alarm), and all interval timers are set to 0 (disabled). 

The vfork(2) system call can be used to fork processes more quickly than fork, but has some restrictions. See vfork(2) for details.

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.  Otherwise, a value of −1 is returned to the parent process, no child process is created, and errno is set to indicate the error. 

The parent and child processes resume execution immediately after the fork call; they are distinguished by the value returned by fork. 

ERRORS

Fork fails and no child process is created if one or more of the following is true:

[EAGAIN] The system-imposed limit on the total number of processes under execution would be exceeded. 

[EAGAIN] The system-imposed limit on the total number of processes under execution by a single user would be exceeded. 

[ENOMEM] There is insufficient swap space and/or physical memory available in which to create the new process. 

WARNINGS

Standard I/O streams (see stdio(3S)) are duplicated in the child. Therefore, if fork is called after a buffered I/O operation without first closing or flushing the associated standard I/O stream (see fclose(3S)), the buffered input or output might be duplicated.

AUTHOR

Fork was developed by AT&T, the University of California, Berkeley, and HP. 

SEE ALSO

acct(2), chroot(2), exec(2), exit(2), fcntl(2), getgroups(2), lockf(2), nice(2), plock(2), profil(2), ptrace(2), rtprio(2), semop(2), setuid(2), setpgrp(2), shmop(2), signal(5), times(2), ulimit(2), umask(2), vfork(2), wait(2), fclose(3S), stdio(3S), acct(4). 

STANDARDS CONFORMANCE

fork: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

Hewlett-Packard Company  —  HP-UX Release 7.0: Sept 1989

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026