fork(S)
fork --
create a new process
Syntax
cc . . . -lc
int fork ()
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 child process inherits the following
attributes from the parent process:
-
environment: see
putenv(S),
getenv(S),
environ(S),
exec(S)
-
close-on-exec flag: see
fcntl(S),
exec(S)
-
signal-handling settings (that is,
SIG_DFL, SIG_IGN, SIG_HOLD,
function address): see
sigaction(S),
signal(M),
and
signal(S)
-
signal mask: see
sigprocmask(S)
-
profiling on/off status: see
profil(S)
-
nice value: see
nice(S)
-
all attached shared memory segments: see
shmop(S)
-
process group ID: see
setpgid(S),
setsid(S),
setpgrp(S),
getpgid(S),
getpgrp(S)
-
tty group ID: see
tcsetpgrp(S),
tcgetpgrp(S),
exit(S)
-
current working directory: see
chdir(S),
getcwd(S)
-
root directory: see
chroot(S)
-
file mode creation mask: see
umask(S)
-
file size limit: see
ulimit(S)
-
real, effective, and saved user IDs: see
setuid(S),
getuid(S),
geteuid(S),
exec(S)
-
real, effective and saved group IDs: see
setgid(S),
getgid(S),
getegid(S),
exec(S)
-
login user ID: see
setluid(S),
getluid(S)
-
supplemental groups: see
setgroups(S),
getgroups(S)
-
controlling terminal
The child process differs from the parent process in the following ways:
-
The child process has a unique process ID: see
getpid(S)
-
The child process has a different parent process ID: see
getppid(S)
-
The child process has its own copy of the parent's file descriptors.
Each of the child's file descriptors shares a common file pointer with the
corresponding file descriptor of the parent.
-
No signals are pending in the child: see
sigpending(S)
-
All semadj values are cleared: see
semop(S)
-
Process locks, text locks, and data locks are not
inherited by the child: see
plock(S),
lock(S)
-
The child process' tms structure is cleared (setting
utime, stime, cutime,
and cstime to 0): see
times(S)
-
The time left until an alarm clock or itimer signal
is reset to 0: see
alarm(S),
setitimer(S),
getitimer(S)
-
Record locks set by the parent are not inherited by the child: see
fcntl(S),
locking(S),
lockf(S)
The fork
system call 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.
-
The system-imposed limit on the total number of processes
under execution by a single user would be exceeded.
-
The total amount of system memory
available when reading via raw I/O
is temporarily insufficient.
[EMFILE]-
The shared data table would overflow.
[ENOMEM]-
The process requires more space than the system can supply.
See also
alarm(S),
exec(S),
getitimer(S),
nice(S),
plock(S),
ptrace(S),
semop(S),
setgid(S),
setgroups(S),
setluid(S),
setuid(S),
shmop(S),
sigaction(S),
signal(M),
signal(S),
sigset(S),
times(S),
ulimit(S),
umask(S),
wait(S)
Diagnostics
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.
Standards conformance
fork is conformant with:
X/Open Portability Guide, Issue 3, 1989
;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1)
;
and
NIST FIPS 151-1
.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003