1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (C) 2005 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Japanese Version Copyright (c) 2005 Akihiro MOTOKI all rights reserved.
26 .\" Translated 2005-12-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
28 .TH PIPE 7 2005-12-08 "Linux" "Linux Programmer's Manual"
31 .\"O pipe \- overview of pipes and FIFOs
35 .\"O Pipes and FIFOs (also known as named pipes)
36 .\"O provide a unidirectional interprocess communication channel.
40 .\"O .IR "write end" .
41 .\"O Data written to the write end of a pipe can be read
42 .\"O from the read end of the pipe.
43 パイプと FIFO (名前付きパイプともいう) は、
45 パイプには「読み出し側」と「書き込み側」がある。
47 パイプの読み出し側から読み出すことができる。
49 .\"O A pipe is created using
51 .\"O which creates a new pipe and returns two file descriptors,
52 .\"O one referring to the read end of the pipe,
53 .\"O the other referring to the write end.
54 .\"O Pipes can be used to create a communication channel between related
62 は新しいパイプを作成し、ファイル・ディスクリプタを二つ返す。
63 ディスクリプタのうち、一方はパイプの読み出し側を、もう一方は
65 パイプは関連するプロセス間の通信を作成するのに使用できる。
70 .\"O A FIFO (short for First In First Out) has a name within the file
71 .\"O system (created using
73 .\"O and is opened using
75 .\"O Any process may open a FIFO, assuming the file permissions allow it.
76 FIFO (First In First Out の省略) はファイルシステムでの名前を持ち、
81 どんなプロセスでも、ファイルのアクセス許可があれば FIFO をオープンする
83 .\"O The read end is opened using the
85 .\"O flag; the write end is opened using the
90 .\"O for further details.
93 フラグを使用し、書き込み側をオープンするには
99 .\"O although FIFOs have a pathname in the file system,
100 .\"O I/O on FIFOs does not involve operations on the underlying device
101 .\"O (if there is one).
103 FIFO はファイルシステム内のパス名を持つが、
104 FIFO に対して入出力を行っても、(ファイルシステムが存在するデバイスが
105 あったとしても) そのデバイスに対する操作は発生しない。
106 .\"O .SS "I/O on Pipes and FIFOs"
107 .SS "パイプや FIFO に対する入出力"
108 .\"O The only difference between pipes and FIFOs is the manner in which
109 .\"O they are created and opened.
110 .\"O Once these tasks have been accomplished,
111 .\"O I/O on pipes and FIFOs has exactly the same semantics.
112 パイプと FIFO の違いは作成やオープンの方法だけである。
113 これらの操作が完了した後は、パイプと FIFO に対する入出力は
116 .\"O If a process attempts to read from an empty pipe, then
118 .\"O will block until data is available.
119 .\"O If a process attempts to write to a full pipe (see below), then
121 .\"O blocks until sufficient data has been read from the pipe
122 .\"O to allow the write to complete.
123 .\"O Nonblocking I/O is possible by using the
126 .\"O operation to enable the
128 .\"O open file status flag.
129 プロセスが空のパイプから読み出しを行おうとした場合、
131 はデータが読み出し可能になるまで停止する。
132 プロセスがフル状態のパイプに書き込みを行おうとした場合、
134 は書き込みを完了するのに十分な量のパイプからの読み出しが
136 非停止 (nonblocking) I/O を使うこともできる。
144 .\"O The communication channel provided by a pipe is a
145 .\"O .IR "byte stream" :
146 .\"O there is no concept of message boundaries.
147 パイプにより提供される通信チャネルは「バイトストリーム」であり、
150 .\"O If all file descriptors referring to the write end of a pipe
151 .\"O have been closed, then an attempt to
153 .\"O from the pipe will see end-of-file
156 パイプの書き込み側を参照しているファイル・ディスクリプタが
160 end-of-file (ファイル末尾) が見える
163 .\"O If all file descriptors referring to the read end of a pipe
164 .\"O have been closed, then a
168 .\"O signal to be generated for the calling process.
169 パイプの読み出し側を参照しているファイル・ディスクリプタが
175 .\"O If the calling process is ignoring this signal, then
177 .\"O fails with the error
179 呼び出し元プロセスがこのシグナルを無視しているときには、
184 .\"O An application that uses
188 .\"O should use suitable
190 .\"O calls to close unnecessary duplicate file descriptors;
191 .\"O this ensures that end-of-file and
192 .\"O .BR SIGPIPE / EPIPE
193 .\"O are delivered when appropriate.
199 を適切に使って不必要なファイル・ディスクリプタの複製を
200 クローズすべきである。こうすることで、必要な時に確実に
205 .\"O It is not possible to apply
211 .\"O .SS "Pipe Capacity"
213 .\"O A pipe has a limited capacity.
214 .\"O If the pipe is full, then a
216 .\"O will block or fail, depending on whether the
218 .\"O flag is set (see below).
219 .\"O Different implementations have different limits for the pipe capacity.
220 .\"O Applications should not rely on a particular capacity:
221 .\"O an application should be designed so that a reading process consumes data
222 .\"O as soon as it is available,
223 .\"O so that a writing process does not remain blocked.
227 は停止したり失敗したりする。どちらになるかは
229 フラグがセットされているかどうかに依存する (下記参照)。
231 アプリケーションは特定の容量を前提にすべきではない。
232 書き込み側のプロセスが停止したままにならないよう、
233 読み出し側のプロセスはデータが利用可能になったらできるだけすぐに
234 読み出しを行うように、アプリケーションを設計すべきである。
236 .\"O In Linux versions before 2.6.11, the capacity of a pipe was the same as
237 .\"O the system page size (e.g., 4096 bytes on i386).
238 .\"O Since Linux 2.6.11, the pipe capacity is 65536 bytes.
239 バージョン 2.6.11 より前の Linux ではパイプの容量はシステムのページサイズ
240 と同じであった (例えば i386 では 4096 バイト)。
241 Linux 2.6.11 以降では、パイプの容量は 65536 バイトである。
244 .\"O POSIX.1-2001 says that
248 .\"O bytes must be atomic: the output data is written to the pipe as a
249 .\"O contiguous sequence.
250 .\"O Writes of more than
252 .\"O bytes may be nonatomic: the kernel may interleave the data
253 .\"O with data written by other processes.
254 .\"O POSIX.1-2001 requires
256 .\"O to be at least 512 bytes.
264 は atomic に行われること、つまりパイプへの出力データの書き込みは
265 連続したシーケンスとして行われることを必須としている (MUST)。
267 バイトより多くのデータを書き込み場合は atomic とはならない、
268 つまりパイプへの他のプロセスによるデータの書き込みが間に入る
272 は最小でも 512 バイトであることが要求されている
276 .\"O The precise semantics depend on whether the file descriptor is nonblocking
277 .\"O .RB ( O_NONBLOCK ),
278 .\"O whether there are multiple writers to the pipe, and on
280 .\"O the number of bytes to be written:
281 正確な動作は、ファイル・ディスクリプタが nonblocking
283 かどうか、パイプへの書き込みが複数から行われるかどうか、および
288 .\"O \fBO_NONBLOCK\fP disabled, \fIn\fP <= \fBPIPE_BUF\fP
289 \fBO_NONBLOCK\fP 無効, \fIn\fP <= \fBPIPE_BUF\fP
292 .\"O bytes are written atomically;
294 .\"O may block if there is not room for
296 .\"O bytes to be written immediately
298 バイト全部の書き込みが atomic に行われる。
304 .\"O \fBO_NONBLOCK\fP enabled, \fIn\fP <= \fBPIPE_BUF\fP
305 \fBO_NONBLOCK\fP 有効, \fIn\fP <= \fBPIPE_BUF\fP
306 .\"O If there is room to write
308 .\"O bytes to the pipe, then
310 .\"O succeeds immediately, writing all
312 .\"O bytes; otherwise
331 .\"O \fBO_NONBLOCK\fP disabled, \fIn\fP > \fBPIPE_BUF\fP
332 \fBO_NONBLOCK\fP 無効, \fIn\fP > \fBPIPE_BUF\fP
333 .\"O The write is nonatomic: the data given to
335 .\"O may be interleaved with
337 .\"O by other process;
342 .\"O bytes have been written.
345 に渡されたデータの間に、他のプロセスにより
353 .\"O \fBO_NONBLOCK\fP enabled, \fIn\fP > \fBPIPE_BUF\fP
354 \fBO_NONBLOCK\fP 有効, \fIn\fP > \fBPIPE_BUF\fP
355 .\"O If the pipe is full, then
361 .\"O Otherwise, from 1 to
363 .\"O bytes may be written (i.e., a "partial write" may occur;
364 .\"O the caller should check the return value from
366 .\"O to see how many bytes were actually written),
367 .\"O and these bytes may be interleaved with writes by other processes.
378 (つまり「一部分だけ書き込まれる」場合もあり得る)。
381 の返り値を参照し、実際に何バイト書き込まれたのかを確認すべきである。
382 また、書き込みに成功したデータも、他のプロセスが書き込んだデータが
384 .\"O .SS "Open File Status Flags"
386 .\"O The only open file status flags that can be meaningfully applied to
387 .\"O a pipe or FIFO are
391 オープンファイル状態フラグのうち、パイプや FIFO に対して意味を持つのは
399 .\"O flag for the read end of a pipe causes a signal
401 .\"O by default) to be generated when new input becomes available on the pipe
407 .\"O is supported for pipes and FIFOs only since kernel 2.6.
410 フラグをセットすると、パイプに新たな入力があるとシグナル (デフォルトでは
418 はカーネル 2.6 以降でのみサポートされている。
419 .\"O .SS "Portability notes"
421 .\"O On some systems (but not Linux), pipes are bidirectional:
422 .\"O data can be transmitted in both directions between the pipe ends.
423 .\"O According to POSIX.1-2001, pipes only need to be unidirectional.
424 .\"O Portable applications should avoid reliance on
425 .\"O bidirectional pipe semantics.
426 いくつかのシステム (Linux ではない) では、パイプは双方向である、
427 つまりパイプの両端間でデータを両方向に送信することができる。
428 POSIX.1-2001 では、パイプは一方向の通信だけに対応していればよい。
429 移植を考慮したアプリケーションでは、双方向パイプの仕組みを