fork.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <html>
  2. <head>
  3. <title>fork</title>
  4. <body bgcolor=#ffffff>
  5. <h2 align=center>fork</h2>
  6. <h4 align=center>OS/161 Reference Manual</h4>
  7. <h3>Name</h3>
  8. fork - copy the current process
  9. <h3>Library</h3>
  10. Standard C Library (libc, -lc)
  11. <h3>Synopsis</h3>
  12. #include &lt;unistd.h&gt;<br>
  13. <br>
  14. pid_t<br>
  15. fork(void);
  16. <h3>Description</h3>
  17. fork duplicates the currently running process. The two copies are
  18. identical, except that one (the "new" one, or "child"), has a new,
  19. unique process id, and in the other (the "parent") the process id is
  20. unchanged.
  21. <p>
  22. The process id must be greater than 0.
  23. <p>
  24. The two processes do not share memory or open file tables; this state
  25. is copied into the new process, and subsequent modification in one
  26. process does not affect the other.
  27. <p>
  28. However, the file handle objects the file tables point to are shared,
  29. so, for instance, calls to lseek in one process can affect the other.
  30. <p>
  31. <h3>Return Values</h3>
  32. On success, fork returns twice, once in the parent process and once in
  33. the child process. In the child process, 0 is returned. In the parent
  34. process, the process id of the new child process is returned.
  35. <p>
  36. On error, no new process is created, fork only returns once, returning
  37. -1, and <A HREF=errno.html>errno</A> is set according to the error
  38. encountered.
  39. <h3>Errors</h3>
  40. The following error codes should be returned under the conditions
  41. given. Other error codes may be returned for other errors not
  42. mentioned here.
  43. <blockquote><table width=90%>
  44. <tr><td width=10%>&nbsp;</td><td>&nbsp;</td></tr>
  45. <tr><td>EMPROC</td> <td>The current user already has too
  46. many processes.</td></tr>
  47. <tr><td>ENPROC</td> <td>There are already too many
  48. processes on the system.</td></tr>
  49. <tr><td>ENOMEM</td> <td>Sufficient virtual memory for the new
  50. process was not available.</td></tr>
  51. </table></blockquote>
  52. </body>
  53. </html>