This file is indexed.

/usr/share/doc/glibc-doc/html/libc_15.html is in glibc-doc 2.15-0ubuntu10.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- This file documents the GNU C library.

This is Edition 0.13, last updated 2011-07-19,
of The GNU C Library Reference Manual, for version
2.14 (Ubuntu EGLIBC 2.15-0ubuntu10) .

Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
2003, 2007, 2008, 2010, 2011 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Free Software Needs Free Documentation"
and "GNU Lesser General Public License", the Front-Cover texts being
"A GNU Manual", and with the Back-Cover Texts as in (a) below.  A
copy of the license is included in the section entitled "GNU Free
Documentation License".

(a) The FSF's Back-Cover Text is: "You have the freedom to
copy and modify this GNU manual.  Buying copies from the FSF
supports it in developing GNU and promoting software freedom."
 -->
<!-- Created on April 20, 2012 by texi2html 1.82
texi2html was written by: 
            Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>The GNU C Library: 15. Pipes and FIFOs</title>

<meta name="description" content="The GNU C Library: 15. Pipes and FIFOs">
<meta name="keywords" content="The GNU C Library: 15. Pipes and FIFOs">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.82">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.roman {font-family:serif; font-weight:normal;}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="Pipes-and-FIFOs"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="libc_14.html#Temporary-Files" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Creating-a-Pipe" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="libc_14.html#File-System-Interface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_16.html#Sockets" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Pipes-and-FIFOs-1"></a>
<h1 class="chapter">15. Pipes and FIFOs</h1>

<a name="index-pipe"></a>
<p>A <em>pipe</em> is a mechanism for interprocess communication; data written
to the pipe by one process can be read by another process.  The data is
handled in a first-in, first-out (FIFO) order.  The pipe has no name; it
is created for one use and both ends must be inherited from the single
process which created the pipe.
</p>
<a name="index-FIFO-special-file"></a>
<p>A <em>FIFO special file</em> is similar to a pipe, but instead of being an
anonymous, temporary connection, a FIFO has a name or names like any
other file.  Processes open the FIFO by name in order to communicate
through it.
</p>
<p>A pipe or FIFO has to be open at both ends simultaneously.  If you read
from a pipe or FIFO file that doesn&rsquo;t have any processes writing to it
(perhaps because they have all closed the file, or exited), the read
returns end-of-file.  Writing to a pipe or FIFO that doesn&rsquo;t have a
reading process is treated as an error condition; it generates a
<code>SIGPIPE</code> signal, and fails with error code <code>EPIPE</code> if the
signal is handled or blocked.
</p>
<p>Neither pipes nor FIFO special files allow file positioning.  Both
reading and writing operations happen sequentially; reading from the
beginning of the file and writing at the end.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Creating-a-Pipe">15.1 Creating a Pipe</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">             Making a pipe with the <code>pipe</code> function.
</td></tr>
<tr><td align="left" valign="top"><a href="#Pipe-to-a-Subprocess">15.2 Pipe to a Subprocess</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">        Using a pipe to communicate with a
				 child process.
</td></tr>
<tr><td align="left" valign="top"><a href="#FIFO-Special-Files">15.3 FIFO Special Files</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">          Making a FIFO special file.
</td></tr>
<tr><td align="left" valign="top"><a href="#Pipe-Atomicity">15.4 Atomicity of Pipe I/O</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">		When pipe (or FIFO) I/O is atomic.
</td></tr>
</table>

<hr size="6">
<a name="Creating-a-Pipe"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Pipes-and-FIFOs" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Pipe-to-a-Subprocess" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Pipes-and-FIFOs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Pipes-and-FIFOs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_16.html#Sockets" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Creating-a-Pipe-1"></a>
<h2 class="section">15.1 Creating a Pipe</h2>
<a name="index-creating-a-pipe"></a>
<a name="index-opening-a-pipe"></a>
<a name="index-interprocess-communication_002c-with-pipes"></a>

<p>The primitive for creating a pipe is the <code>pipe</code> function.  This
creates both the reading and writing ends of the pipe.  It is not very
useful for a single process to use a pipe to talk to itself.  In typical
use, a process creates a pipe just before it forks one or more child
processes (see section <a href="libc_26.html#Creating-a-Process">Creating a Process</a>).  The pipe is then used for
communication either between the parent or child processes, or between
two sibling processes.
</p>
<p>The <code>pipe</code> function is declared in the header file
&lsquo;<tt>unistd.h</tt>&rsquo;.
<a name="index-unistd_002eh-12"></a>
</p>
<dl>
<dt><a name="index-pipe-1"></a><u>Function:</u> int <b>pipe</b><i> (int <var>filedes</var><tt>[2]</tt>)</i></dt>
<dd><p>The <code>pipe</code> function creates a pipe and puts the file descriptors
for the reading and writing ends of the pipe (respectively) into
<code><var>filedes</var>[0]</code> and <code><var>filedes</var>[1]</code>.
</p>
<p>An easy way to remember that the input end comes first is that file
descriptor <code>0</code> is standard input, and file descriptor <code>1</code> is
standard output.
</p>
<p>If successful, <code>pipe</code> returns a value of <code>0</code>.  On failure,
<code>-1</code> is returned.  The following <code>errno</code> error conditions are
defined for this function:
</p>
<dl compact="compact">
<dt> <code>EMFILE</code></dt>
<dd><p>The process has too many files open.
</p>
</dd>
<dt> <code>ENFILE</code></dt>
<dd><p>There are too many open files in the entire system.  See section <a href="libc_2.html#Error-Codes">Error Codes</a>,
for more information about <code>ENFILE</code>.  This error never occurs in
the GNU system.
</p></dd>
</dl>
</dd></dl>

<p>Here is an example of a simple program that creates a pipe.  This program
uses the <code>fork</code> function (see section <a href="libc_26.html#Creating-a-Process">Creating a Process</a>) to create
a child process.  The parent process writes data to the pipe, which is
read by the child process.
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">#include &lt;sys/types.h&gt;
#include &lt;unistd.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

/* <span class="roman">Read characters from the pipe and echo them to <code>stdout</code>.</span> */

void
read_from_pipe (int file)
{
  FILE *stream;
  int c;
  stream = fdopen (file, &quot;r&quot;);
  while ((c = fgetc (stream)) != EOF)
    putchar (c);
  fclose (stream);
}

/* <span class="roman">Write some random text to the pipe.</span> */

void
write_to_pipe (int file)
{
  FILE *stream;
  stream = fdopen (file, &quot;w&quot;);
  fprintf (stream, &quot;hello, world!\n&quot;);
  fprintf (stream, &quot;goodbye, world!\n&quot;);
  fclose (stream);
}

int
main (void)
{
  pid_t pid;
  int mypipe[2];

</pre><pre class="smallexample">  /* <span class="roman">Create the pipe.</span> */
  if (pipe (mypipe))
    {
      fprintf (stderr, &quot;Pipe failed.\n&quot;);
      return EXIT_FAILURE;
    }
</pre><pre class="smallexample">
  /* <span class="roman">Create the child process.</span> */
  pid = fork ();
  if (pid == (pid_t) 0)
    {
      /* <span class="roman">This is the child process.
         Close other end first.</span> */
      close (mypipe[1]);
      read_from_pipe (mypipe[0]);
      return EXIT_SUCCESS;
    }
  else if (pid &lt; (pid_t) 0)
    {
      /* <span class="roman">The fork failed.</span> */
      fprintf (stderr, &quot;Fork failed.\n&quot;);
      return EXIT_FAILURE;
    }
  else
    {
      /* <span class="roman">This is the parent process.
         Close other end first.</span> */
      close (mypipe[0]);
      write_to_pipe (mypipe[1]);
      return EXIT_SUCCESS;
    }
}
</pre></td></tr></table>

<hr size="6">
<a name="Pipe-to-a-Subprocess"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Creating-a-Pipe" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#FIFO-Special-Files" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Pipes-and-FIFOs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Pipes-and-FIFOs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_16.html#Sockets" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Pipe-to-a-Subprocess-1"></a>
<h2 class="section">15.2 Pipe to a Subprocess</h2>
<a name="index-creating-a-pipe-to-a-subprocess"></a>
<a name="index-pipe-to-a-subprocess"></a>
<a name="index-filtering-i_002fo-through-subprocess"></a>

<p>A common use of pipes is to send data to or receive data from a program
being run as a subprocess.  One way of doing this is by using a combination of
<code>pipe</code> (to create the pipe), <code>fork</code> (to create the subprocess),
<code>dup2</code> (to force the subprocess to use the pipe as its standard input
or output channel), and <code>exec</code> (to execute the new program).  Or,
you can use <code>popen</code> and <code>pclose</code>.
</p>
<p>The advantage of using <code>popen</code> and <code>pclose</code> is that the
interface is much simpler and easier to use.  But it doesn&rsquo;t offer as
much flexibility as using the low-level functions directly.
</p>
<dl>
<dt><a name="index-popen"></a><u>Function:</u> FILE * <b>popen</b><i> (const char *<var>command</var>, const char *<var>mode</var>)</i></dt>
<dd><p>The <code>popen</code> function is closely related to the <code>system</code>
function; see <a href="libc_26.html#Running-a-Command">Running a Command</a>.  It executes the shell command
<var>command</var> as a subprocess.  However, instead of waiting for the
command to complete, it creates a pipe to the subprocess and returns a
stream that corresponds to that pipe.
</p>
<p>If you specify a <var>mode</var> argument of <code>&quot;r&quot;</code>, you can read from the
stream to retrieve data from the standard output channel of the subprocess.
The subprocess inherits its standard input channel from the parent process.
</p>
<p>Similarly, if you specify a <var>mode</var> argument of <code>&quot;w&quot;</code>, you can
write to the stream to send data to the standard input channel of the
subprocess.  The subprocess inherits its standard output channel from
the parent process.
</p>
<p>In the event of an error <code>popen</code> returns a null pointer.  This
might happen if the pipe or stream cannot be created, if the subprocess
cannot be forked, or if the program cannot be executed.
</p></dd></dl>

<dl>
<dt><a name="index-pclose"></a><u>Function:</u> int <b>pclose</b><i> (FILE *<var>stream</var>)</i></dt>
<dd><p>The <code>pclose</code> function is used to close a stream created by <code>popen</code>.
It waits for the child process to terminate and returns its status value,
as for the <code>system</code> function.
</p></dd></dl>

<p>Here is an example showing how to use <code>popen</code> and <code>pclose</code> to
filter output through another program, in this case the paging program
<code>more</code>.
</p>
<table><tr><td>&nbsp;</td><td><pre class="smallexample">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

void
write_data (FILE * stream)
{
  int i;
  for (i = 0; i &lt; 100; i++)
    fprintf (stream, &quot;%d\n&quot;, i);
  if (ferror (stream))
    {
      fprintf (stderr, &quot;Output to stream failed.\n&quot;);
      exit (EXIT_FAILURE);
    }
}

</pre><pre class="smallexample">int
main (void)
{
  FILE *output;

  output = popen (&quot;more&quot;, &quot;w&quot;);
  if (!output)
    {
      fprintf (stderr,
               &quot;incorrect parameters or too many files.\n&quot;);
      return EXIT_FAILURE;
    }
  write_data (output);
  if (pclose (output) != 0)
    {
      fprintf (stderr,
               &quot;Could not run more or other error.\n&quot;);
    }
  return EXIT_SUCCESS;
}
</pre></td></tr></table>

<hr size="6">
<a name="FIFO-Special-Files"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Pipe-to-a-Subprocess" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Pipe-Atomicity" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Pipes-and-FIFOs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Pipes-and-FIFOs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_16.html#Sockets" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="FIFO-Special-Files-1"></a>
<h2 class="section">15.3 FIFO Special Files</h2>
<a name="index-creating-a-FIFO-special-file"></a>
<a name="index-interprocess-communication_002c-with-FIFO"></a>

<p>A FIFO special file is similar to a pipe, except that it is created in a
different way.  Instead of being an anonymous communications channel, a
FIFO special file is entered into the file system by calling
<code>mkfifo</code>.
</p>
<p>Once you have created a FIFO special file in this way, any process can
open it for reading or writing, in the same way as an ordinary file.
However, it has to be open at both ends simultaneously before you can
proceed to do any input or output operations on it.  Opening a FIFO for
reading normally blocks until some other process opens the same FIFO for
writing, and vice versa.
</p>
<p>The <code>mkfifo</code> function is declared in the header file
&lsquo;<tt>sys/stat.h</tt>&rsquo;.
<a name="index-sys_002fstat_002eh-7"></a>
</p>
<dl>
<dt><a name="index-mkfifo"></a><u>Function:</u> int <b>mkfifo</b><i> (const char *<var>filename</var>, mode_t <var>mode</var>)</i></dt>
<dd><p>The <code>mkfifo</code> function makes a FIFO special file with name
<var>filename</var>.  The <var>mode</var> argument is used to set the file&rsquo;s
permissions; see <a href="libc_14.html#Setting-Permissions">Assigning File Permissions</a>.
</p>
<p>The normal, successful return value from <code>mkfifo</code> is <code>0</code>.  In
the case of an error, <code>-1</code> is returned.  In addition to the usual
file name errors (see section <a href="libc_11.html#File-Name-Errors">File Name Errors</a>), the following
<code>errno</code> error conditions are defined for this function:
</p>
<dl compact="compact">
<dt> <code>EEXIST</code></dt>
<dd><p>The named file already exists.
</p>
</dd>
<dt> <code>ENOSPC</code></dt>
<dd><p>The directory or file system cannot be extended.
</p>
</dd>
<dt> <code>EROFS</code></dt>
<dd><p>The directory that would contain the file resides on a read-only file
system.
</p></dd>
</dl>
</dd></dl>

<hr size="6">
<a name="Pipe-Atomicity"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#FIFO-Special-Files" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="libc_16.html#Sockets" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Pipes-and-FIFOs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Pipes-and-FIFOs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="libc_16.html#Sockets" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Atomicity-of-Pipe-I_002fO"></a>
<h2 class="section">15.4 Atomicity of Pipe I/O</h2>

<p>Reading or writing pipe data is <em>atomic</em> if the size of data written
is not greater than <code>PIPE_BUF</code>.  This means that the data transfer
seems to be an instantaneous unit, in that nothing else in the system
can observe a state in which it is partially complete.  Atomic I/O may
not begin right away (it may need to wait for buffer space or for data),
but once it does begin it finishes immediately.
</p>
<p>Reading or writing a larger amount of data may not be atomic; for
example, output data from other processes sharing the descriptor may be
interspersed.  Also, once <code>PIPE_BUF</code> characters have been written,
further writes will block until some characters are read.
</p>
<p>See section <a href="libc_31.html#Limits-for-Files">Limits on File System Capacity</a>, for information about the <code>PIPE_BUF</code>
parameter.
</p><hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Pipes-and-FIFOs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="libc_16.html#Sockets" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="libc.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="libc_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="libc_42.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="libc_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated by <em>root</em> on <em>April 20, 2012</em> using <a href="http://www.nongnu.org/texi2html/"><em>texi2html 1.82</em></a>.
 </font>
 <br>

</p>
</body>
</html>