Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fork(2) — AIX/RT 2.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exec: execl, execv, execle, execve, execlp, execvp

exit, _exit

nice

plock

ptrace

semop

shmat

signal

sigvec

times

ulimit

umask

wait

shlib

fork

Purpose

     Creates a new process.

Syntax

     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 created  child  process
     inherits  the   following  attributes  from   the  parent
     process:

     o   Environment
     o   Close-on-exec  flags   (see  "exec:    execl,  execv,
         execle, execve, execlp, execvp")
     o   Signal handling settings  (that is, SIG_DFL, SIG_IGN,
         function address)
     o   Set-user-ID mode bit
     o   Set-group-ID mode bit
     o   Profiling on/off status
     o   Nice value (see "nice")
     o   All attached  shared libraries (see shlib  command in
         AIX Operating System Commands Reference)
     o   Process group ID
     o   TTY group ID (see "exit, _exit" and "signal")
     o   Current directory
     o   Root directory
     o   File mode creation mask (see "umask")
     o   File size limit (see "ulimit")
     o   Attached shared memory segments (see "shmat") &c2del.
     o   Attached mapped file segments (see "shmat").  &c2off.
         &c2ins.
     o   Attached mapped file segments (see "shmat")
     o   Login user ID
     o   Suspend/resume process audit flag (see "auditproc")
     o   General/special  user  audit  flag  (see  "auditsys")
         &c2off.

     The child process differs from  the parent process in the
     following ways:

     o   The child process has a unique process ID.

     o   The child  process has as  its parent process  ID the
         process ID of the parent process.

     o   The child  process has its  own copy of  the parent's
         file descriptors.  However, each  of the child's file

         descriptors  shares a  common file  pointer with  the
         corresponding file descriptor of the parent process.

     o   All  semadj  values  are cleared.   (For  information
         about semadj values, see "semop.")

     o   Process  locks, text  locks  and data  locks are  not
         inherited  by  the  child.   (For  information  about
         locks, see "plock.")

     o   The child process's trace flag (see the discussion of
         request  0 of  "ptrace") is  false regardless  of the
         value of the parent process's trace flag.

     o   The child process's utime,  stime, cutime, and cstime
         are set to 0.  (See "times.")

     o   Any pending  alarms are  cleared in the  child.  (See
         "alarm.")

     o   The child process will  inherit the parent's debugger
         process ID  and multi-process flag if  the parent has
         multi-process debugging enabled.  (See "ptrace.")

Return Value

     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.  If fork fails, a value of
     -1 is returned to the parent process, no child process is
     created, and errno is set to indicate the error.

Diagnostics

     The fork  system call fails  if one  or more of  the fol-
     lowing are true:

     EAGAIN     The system-imposed  limit on the  total number
                of processes executing would be exceeded.

     EAGAIN     The system-imposed  limit on the  total number
                of processes executing for a single user would
                be exceeded.

     ENOMEM     There  is  not  enough  space  left  for  this
                process.

Related Information

     In  this book:   "exec:   execl,  execv, execle,  execve,
     execlp,  execvp,"   "exit,   _exit,"   "nice,"  "plock,"
     "ptrace,"    "semop,"   "shmat,"    "signal,"   "sigvec,"
     "times,"  "ulimit,"  "umask," and "wait."

     The shlib command in AIX Operating System Commands Refer-
     ence.

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