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

FreeBSD Manual Pages

  
 
  

home | help
FORK(2V)							      FORK(2V)

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:

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

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

       o  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	estab-
	  lish standard	input and output for newly created processes  as  well
	  as to	set up pipes.

       o  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	corre-
	  sponding directory stream of the parent.

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

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

       o  The child process's  values  of  tms_utime(),	 tms_stime(),  tms_cu-
	  time(), and tms_cstime() (see	times(3V)) are set to zero.

       o  File	locks (see fcntl(2V)) previously set by	the parent are not in-
	  herited by the child.

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

       o  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 er-
       ror, 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 pro-
		      cesses under execution would be exceeded.	 This limit is
		      determined when the system is generated.

		      The  system-imposed  limit  on  the total	number of pro-
		      cesses under execution by	a single  user	would  be  ex-
		      ceeded.	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)

				21 January 1990			      FORK(2V)

NAME | SYNOPSIS | SYSTEM V SYNOPSIS | DESCRIPTION | RETURN VALUES | ERRORS | SEE ALSO

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=fork&sektion=2v&manpath=SunOS+4.1.3>

home | help