fork.2 (2010 09)

f
fork(2) fork(2)
Fine-grained privileges are inherited through a calculation to determine which, if any, of the parent
process privileges are inherited by the child.
The
vfork() system call can be used to fork processes more quickly than
fork(), but has some restric-
tions. See vfork (2) for details.
If a parent and child process both have a file opened and the parent or child closes the file, the file is still
open for the other process.
Security Restrictions
This system call requires the
LIMIT privilege in order to exceed the per-user process limit Processes
owned by the superuser have this privilege. Processes owned by other users may have this privilege,
depending on system configuration. See privileges (5) for more information about privileged access on sys-
tems that support fine-grained privileges.
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 dis-
tinguished by the value returned by
fork().
ERRORS
If
fork() fails, errno is set to one of the following values.
[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 insufcient swap space and/or physical memory available in which to
create the new process.
[EPERM] The
PRIV_FORK privilege is not present in the effective set of the calling 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.
DEPENDENCIES
HP Process Resource Manager
If the optional HP Process Resource Manager (PRM) software is installed and configured, the child pro-
cess inherits the parent’s process resource group ID. See prmconfig(1) for a description of how to
configure HP PRM, and prmconf (4) for the definition of process resource group.
AUTHOR
fork() was developed by AT&T, the University of California, Berkeley, and HP.
SEE ALSO
coreadm(1M), acct(2), chroot(2), coreadm(2), exec(2), exit(2), fcntl(2), getgroups(2), lockf(2), nice(2),
plock(2), profil(2), pthread_atfork(3T), ttrace(2), rtprio(2), semop(2), setpgrp(2), setuid(2), shmop(2),
times(2), ulimit(2), umask(2), vfork(2), wait(2), fclose(3S), stdio(3S), acct(4), compartments(5),
privileges(5), signal(5).
HP Process Resource Manager: prmconfig(1), prmconf(4) in HP Process Resource Manager Users Guide.
STANDARDS CONFORMANCE
fork(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1
2 Hewlett-Packard Company 2 HP-UX 11i Version 3: September 2010