/* [<][>][^][v][top][bottom][index][help] */
<html>
<head>
<title>fork</title>
<body bgcolor=#ffffff>
<h2 align=center>fork</h2>
<h4 align=center>OS/161 Reference Manual</h4>
<h3>Name</h3>
fork - copy the current process
<h3>Library</h3>
Standard C Library (libc, -lc)
<h3>Synopsis</h3>
#include <unistd.h><br>
<br>
pid_t<br>
fork(void);
<h3>Description</h3>
fork duplicates the currently running process. The two copies are
identical, except that one (the "new" one, or "child"), has a new,
unique process id, and in the other (the "parent") the process id is
unchanged.
<p>
The process id must be greater than 0.
<p>
The two processes do not share memory or open file tables; this state
is copied into the new process, and subsequent modification in one
process does not affect the other.
<p>
However, the file handle objects the file tables point to are shared,
so, for instance, calls to lseek in one process can affect the other.
<p>
<h3>Return Values</h3>
On success, fork returns twice, once in the parent process and once in
the child process. In the child process, 0 is returned. In the parent
process, the process id of the new child process is returned.
<p>
On error, no new process is created, fork only returns once, returning
-1, and <A HREF=errno.html>errno</A> is set according to the error
encountered.
<h3>Errors</h3>
The following error codes should be returned under the conditions
given. Other error codes may be returned for other errors not
mentioned here.
<blockquote><table width=90%>
<tr><td width=10%> </td><td> </td></tr>
<tr><td>EMPROC</td> <td>The current user already has too
many processes.</td></tr>
<tr><td>ENPROC</td> <td>There are already too many
processes on the system.</td></tr>
<tr><td>ENOMEM</td> <td>Sufficient virtual memory for the new
process was not available.</td></tr>
</table></blockquote>
</body>
</html>