Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fork(2V) — SunOS 4.1.2

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

execve(2V)

getitimer(2)

getrlimit(2)

lseek(2V)

read(2V)

semop(2)

wait(2V)

write(2V)

FORK(2V)  —  SYSTEM CALLS

NAME

fork − create a new process

SYNOPSIS

int fork()

SYSTEM V SYNOPSIS

pid_t fork()

DESCRIPTION

fork() creates a new process.  The new process (child process) is an exact copy of the calling process except for the following:

• The child process has a unique process ID.  The child process ID also does not match any active process group ID. 

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

• The child process has its own copy of the parent’s descriptors.  These descriptors reference the same underlying objects, so that, for instance, file pointers in file objects are shared between the child and the parent, so that an lseek(2V)) on a descriptor in the child process can affect a subsequent read(2V) or write(2V) by the parent.  This descriptor copying is also used by the shell to establish standard input and output for newly created processes as well as to set up pipes. 

• The child process has its own copy of the parent’s open directory streams (see directory(3V)).  Each open directory stream in the child process shares directory stream positioning with the corresponding directory stream of the parent. 

• All semadj values are cleared; see semop(2). 

• The child processes resource utilizations are set to 0; see getrlimit(2).  The it_value and it_interval values for the ITIMER_REAL timer are reset to 0; see getitimer(2). 

• The child process’s values of tms_utime(), tms_stime(), tms_cutime(), and tms_cstime() (see times(3V)) are set to zero. 

• File locks (see fcntl(2V)) previously set by the parent are not inherited by the child. 

• Pending alarms (see alarm(3V)) are cleared for the child process. 

• The set of signals pending for the child process is cleared (see sigvec(2)). 

RETURN VALUES

On success, fork() returns 0 to the child process and returns the process ID of the child process to the parent process.  On failure, fork() returns −1 to the parent process, sets errno to indicate the error, and no child process is created. 

ERRORS

fork() will fail and no child process will be created if one or more of the following are true:

EAGAIN The system-imposed limit on the total number of processes under execution would be exceeded.  This limit is determined when the system is generated. 

The system-imposed limit on the total number of processes under execution by a single user would be exceeded.  This limit is determined when the system is generated. 

ENOMEM There is insufficient swap space for the new process. 

SEE ALSO

execve(2V), getitimer(2), getrlimit(2), lseek(2V), read(2V), semop(2), wait(2V), write(2V)

Sun Release 4.1  —  Last change: 21 January 1990

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