fork.2 (2010 09)
f
fork(2) fork(2)
NAME
fork() - create a new process
SYNOPSIS
#include <unistd.h>
pid_t fork(void);
DESCRIPTION
The fork() system call causes the creation of a new process. The new child process is created with
exactly one thread or lightweight process. The new child process contains a replica of the calling thread
(if the calling process is multi-threaded) and its entire address space, possibly including the state of
mutexes and other resources.
If the calling process is multi-threaded, the child process may only execute async-signal safe functions
until one of the exec functions is called. Fork handlers may be installed via
pthread_atfork()
in
order to maintain application invariants across
fork() calls (i.e, release resources such as mutexes in
the child process).
The child process inherits the following attributes from the parent process:
• Real, effective, and saved user IDs.
• Real, effective, and saved group IDs.
• 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 sigprocmask (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)).
• Fine-grained privileges (if installed) (see privileges (5)).
• Compartments (if installed and enabled) (see compartments (5)).
• The trace flag (see the ttrace (2) TT_PROC_SETTRC
request).
• Core file settings (see coreadm (2) and coreadm (1M)).
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 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
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 for
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).
HP-UX 11i Version 3: September 2010 − 1 − Hewlett-Packard Company 1