Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fork(2) — Ultrix-11 3.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exec(2)

wait(2)

fork(2)

NAME

fork − spawn new process

SYNTAX

int fork()

DESCRIPTION

The fork system call creates new processes.  The core image of the new process is a copy of the core image of the calling process.  The only distinction is that the value returned in the old (parent) process contains the process ID of the new (child) process, while the value returned in the child is 0.  Process IDs range from 1 to 30,000.  This process ID is used by the wait call.  The child process inherits the following attributes from the parent process:

environment
close-on-exec flag                     See exec(2)
signal handling settings (SIG_DFL, SIG_ING, function address)
set-user-ID mode bit
set-group-ID mode bit
profiling on/off status
nice value                             See nice(2)
process group ID
tty group ID                           See exit(2) and signal(2)
trace flag                             See ptrace(2) request 0
time left until an alarm clock signal  See alarm(2)
current working directory
root directory
file mode creation mask                See umask(2)
file size limit                        See ulimit(2)

The child process, however, differs from the parent process:

•The child process has a unique process ID. 

•The child process has a different parent process ID (that is, the process ID of the parent process). 

•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. 

•All semadj values are cleared.  For further information, see semop(2). 

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

•The child process’s utime, stime, cutime, and cstime are set to 0.  The time left until an alarm clock signal is reset to 0. 

Files that are opened before the fork call are shared and have a common read-write pointer.  In particular, standard input and output files are passed and also pipes are set up in this way. 

RESTRICTIONS

Only the superuser can take the last slot in the process table. 

RETURN VALUE

If successful, returns a to the child process and the process ID of the child process to the parent process.  If unsuccessful, returns a −1 to the parent process, and the global variable errno indicates the error code. 

DIAGNOSTICS

The fork call will fail if:

[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 no swap space available for maxmem. 

ASSEMBLER

(fork = 2.) 
sys fork
(new process return)
(old process return, new process ID in r0)

The return locations in the old and new process differ by one word.  The C-bit is set in the old process if a new process could not be created. 

SEE ALSO

exec(2), wait(2)

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