fork(S-osr5)
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-osr5),
getenv(S-osr5),
environ(S-osr5),
exec(S-osr5)
-
close-on-exec flag: see
fcntl(S-osr5),
exec(S-osr5)
-
signal-handling settings (that is,
SIG_DFL, SIG_IGN, SIG_HOLD,
function address): see
sigaction(S-osr5),
signal(M),
and
signal(S-osr5)
-
signal mask: see
sigprocmask(S-osr5)
-
profiling on/off status: see
profil(S-osr5)
-
nice value: see
nice(S-osr5)
-
all attached shared memory segments: see
shmop(S-osr5)
-
process group ID: see
setpgid(S-osr5),
setsid(S-osr5),
setpgrp(S-osr5),
getpgid(S-osr5),
getpgrp(S-osr5)
-
tty group ID: see
tcsetpgrp(S-osr5),
tcgetpgrp(S-osr5),
exit(S-osr5)
-
current working directory: see
chdir(S-osr5),
getcwd(S-osr5)
-
root directory: see
chroot(S-osr5)
-
file mode creation mask: see
umask(S-osr5)
-
file size limit: see
ulimit(S-osr5)
-
real, effective, and saved user IDs: see
setuid(S-osr5),
getuid(S-osr5),
geteuid(S-osr5),
exec(S-osr5)
-
real, effective and saved group IDs: see
setgid(S-osr5),
getgid(S-osr5),
getegid(S-osr5),
exec(S-osr5)
-
login user ID: see
setluid(S-osr5),
getluid(S-osr5)
-
supplemental groups: see
setgroups(S-osr5),
getgroups(S-osr5)
-
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-osr5)
-
The child process has a different parent process ID: see
getppid(S-osr5)
-
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-osr5)
-
All semadj values are cleared: see
semop(S-osr5)
-
Process locks, text locks, and data locks are not
inherited by the child: see
plock(S-osr5),
lock(S-osr5)
-
The child process' tms structure is cleared (setting
utime, stime, cutime,
and cstime to 0): see
times(S-osr5)
-
The time left until an alarm clock or itimer signal
is reset to 0: see
alarm(S-osr5),
setitimer(S-osr5),
getitimer(S-osr5)
-
Record locks set by the parent are not inherited by the child: see
fcntl(S-osr5),
locking(S-osr5),
lockf(S-osr5)
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-osr5),
exec(S-osr5),
getitimer(S-osr5),
nice(S-osr5),
plock(S-osr5),
ptrace(S-osr5),
semop(S-osr5),
setgid(S-osr5),
setgroups(S-osr5),
setluid(S-osr5),
setuid(S-osr5),
shmop(S-osr5),
sigaction(S-osr5),
signal(M),
signal(S-osr5),
sigset(S-osr5),
times(S-osr5),
ulimit(S-osr5),
umask(S-osr5),
wait(S-osr5)
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
.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005