Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
fork(2)			      System Calls Manual		       fork(2)

       fork - create a new process

       The  system  call  causes  the creation of a new	process. The new child
       process is created wth exactly one thread or lightweight	 process.  The
       new  child  process  contains  a	 replica of the	calling	thread (if the
       calling process is multi-threaded) and its entire address space,	possi-
       bly including the state of mutexes and other resources.

       If  the	calling	 process is multi-threaded, the	child process may only
       execute async-signal safe functions until one of	the exec functions  is
       called.	Fork handlers may be installed via in order to maintain	appli-
       cation invariants across	calls (i.e, release resources such as  mutexes
       in the child process).

       The  child  process  inherits  the following attributes from the	parent

	      o	 Real, effective, and saved user IDs.
	      o	 Real, effective, and saved group IDs.
	      o	 List of supplementary group IDs (see getgroups(2)).
	      o	 Process group ID.
	      o	 Environment.
	      o	 File descriptors.
	      o	 Close-on-exec flags (see exec(2)).
	      o	 Signal	handling settings address).
	      o	 Signal	mask (see sigvector(2)).
	      o	 Profiling on/off status (see profil(2)).
	      o	 Command name in the accounting	record (see acct(4)).
	      o	 Nice value (see nice(2)).
	      o	 All attached shared memory segments (see shmop(2)).
	      o	 Current working directory
	      o	 Root directory	(see chroot(2)).
	      o	 File mode creation mask (see umask(2)).
	      o	 File size limit (see ulimit(2)).
	      o	 Real-time priority (see rtprio(2)).

       Each of the child's file	descriptors shares a common open file descrip-
       tion  with  the	corresponding file descriptor of the parent.  This im-
       plies that changes to the file offset, file access mode,	and file  sta-
       tus  flags  of  file descriptors	in the parent also affect those	in the
       child, and vice-versa.

       The child process differs from the  parent  process  in	the  following

	      The child	process	has a unique process ID.

	      The child	process	ID does	not match any active process group ID.

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

	      The set of signals pending for the child process is  initialized
	      to the empty set.

	      The  trace  flag	(see  the ptrace(2) request) is	cleared	in the
	      child process.

	      The flag in the component	of the accounting record is set	in the
	      child process.

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

	      All values are cleared (see semop(2)).

	      The child	 process's  values  for	 and  are  set	to  zero  (see

	      The  time	left until an alarm clock signal is reset to 0 (clear-
	      ing any pending alarm), and all interval timers  are  set	 to  0

       The  vfork(2)  system  call  can	be used	to fork	processes more quickly
       than but	has some restrictions.	See vfork(2) for details.

       If a parent and child process both have a file opened and the parent or
       child closes the	file, the file is still	open for the other process.

       Upon successful completion, returns a value of 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 is set to indicate the error.

       The parent and child processes resume execution immediately  after  the
       call; they are distinguished by the value returned by

       If fails, is set	to one of the following	values.

	      [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 insufficient swap	space and/or  physical
			     memory  available	in  which  to  create  the new

       Standard	I/O streams (see  stdio(3S))  are  duplicated  in  the	child.
       Therefore,  if  is  called after	a buffered I/O operation without first
       closing	or  flushing  the  associated	standard   I/O	 stream	  (see
       fclose(3S)), the	buffered input or output might be duplicated.

   HP Process Resource Manager
       If the optional HP Process Resource Manager (PRM) software is installed
       and configured, the child process inherits  the	parent's  process  re-
       source  group ID.  See prmconfig(1) for a description of	how to config-
       ure HP PRM, and prmconf(4)  for	the  definition	 of  process  resource

       was developed by	AT&T, the University of	California, Berkeley, and HP.

       acct(2),	chroot(2), exec(2), exit(2), fcntl(2), getgroups(2), lockf(2),
       nice(2),	plock(2), profil(2), pthread_atfork(3T), ptrace(2), rtprio(2),
       semop(2),   setpgrp(2),	 setuid(2),   shmop(2),	 times(2),  ulimit(2),
       umask(2), vfork(2), wait(2), fclose(3S),	stdio(3S), acct(4), signal(5).

       HP Process Resource Manager: prmconfig(1), prmconf(4) in



Want to link to this manual page? Use this URL:

home | help