pipe.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <html>
  2. <head>
  3. <title>pipe</title>
  4. <body bgcolor=#ffffff>
  5. <h2 align=center>pipe</h2>
  6. <h4 align=center>OS/161 Reference Manual</h4>
  7. <h3>Name</h3>
  8. pipe - create pipe object
  9. <h3>Library</h3>
  10. Standard C Library (libc, -lc)
  11. <h3>Synopsis</h3>
  12. #include &lt;unistd.h&gt;<br>
  13. <br>
  14. int<br>
  15. pipe(int *<em>fds</em>);
  16. <h3>Description</h3>
  17. The pipe call creates an anonymous pipe object in the system, and
  18. binds it to two file handles in the current process, one for the read
  19. end and one for the write end. (Pipes are unidirectional.)
  20. <p>
  21. Data written on the write end may be read from the read end. Once all
  22. references to the write end are closed, and all remaining data is
  23. read, further reads return EOF. If all references to the read end are
  24. closed before the write end is closed, further writes generate
  25. errors. The pipe object itself is destroyed when all references to
  26. both ends are closed.
  27. <p>
  28. <em>fds</em> is a pointer to two integers. A file handle for the read
  29. end of the pipe is stored in <em>fds</em>[0], and a file handle for
  30. the write end is stored in <em>fds</em>[1].
  31. <p>
  32. pipe is most often used in conjunction with <A HREF=dup2.html>dup2</A>
  33. and <A HREF=fork.html>fork</A> to send the standard output of one
  34. process to the standard input of another.
  35. <p>
  36. In POSIX, pipe I/O of data blocks smaller than a standard constant
  37. PIPE_BUF is guaranteed to be atomic. If you implement pipes, you need
  38. not necessarily implement POSIX semantics, but you should decide what
  39. sort of atomicity guarantees you wish to make and specify them
  40. carefully.
  41. <h3>Return Values</h3>
  42. On success, pipe returns 0. On error, -1 is returned, and
  43. <A HREF=errno.html>errno</A> is set according to the error
  44. encountered.
  45. <h3>Errors</h3>
  46. The following error codes should be returned under the conditions
  47. given. Other error codes may be returned for other errors not
  48. mentioned here.
  49. <blockquote><table width=90%>
  50. <td width=10%>&nbsp;</td><td>&nbsp;</td></tr>
  51. <tr><td>EMFILE</td> <td>The process's file table was full, or a
  52. process-specific limit on open files
  53. was reached.</td></tr>
  54. <tr><td>ENFILE</td> <td>The system file table is full, if such a
  55. thing exists, or a system-wide limit
  56. on open files was reached.</td></tr>
  57. <tr><td>EFAULT</td> <td><em>fds</em> was an invalid pointer.</td></tr>
  58. </table></blockquote>
  59. </body>
  60. </html>