OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / draft / man7 / pipe.7
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (C) 2005 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
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.
8 .\"
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.
13 .\"
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
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" Japanese Version Copyright (c) 2005 Akihiro MOTOKI all rights reserved.
26 .\" Translated 2005-12-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
27 .\"
28 .TH PIPE 7 2005-12-08 "Linux" "Linux Programmer's Manual"
29 .\"O .SH NAME
30 .SH 名前
31 .\"O pipe \- overview of pipes and FIFOs
32 pipe \- パイプと FIFO の概要
33 .\"O .SH DESCRIPTION
34 .SH 説明
35 .\"O Pipes and FIFOs (also known as named pipes)
36 .\"O provide a unidirectional interprocess communication channel.
37 .\"O A pipe has a
38 .\"O .I read end
39 .\"O and a
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 (名前付きパイプともいう) は、
44 単方向のプロセス間通信チャネルを提供する。
45 パイプには「読み出し側」と「書き込み側」がある。
46 パイプの書き込み側で書き込まれたデータは、
47 パイプの読み出し側から読み出すことができる。
48
49 .\"O A pipe is created using
50 .\"O .BR pipe (2),
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
55 .\"O processes; see
56 .\"O .BR pipe (2)
57 .\"O for an example.
58 パイプを作成するには
59 .BR pipe (2)
60 を使用する。
61 .BR pipe (2)
62 は新しいパイプを作成し、ファイル・ディスクリプタを二つ返す。
63 ディスクリプタのうち、一方はパイプの読み出し側を、もう一方は
64 書き込み側を参照している。
65 パイプは関連するプロセス間の通信を作成するのに使用できる。
66 例は
67 .BR pipe (2)
68 を参照。
69
70 .\"O A FIFO (short for First In First Out) has a name within the file
71 .\"O system (created using
72 .\"O .BR mkfifo (3)),
73 .\"O and is opened using
74 .\"O .BR open (2).
75 .\"O Any process may open a FIFO, assuming the file permissions allow it.
76 FIFO (First In First Out の省略) はファイルシステムでの名前を持ち、
77 .BR open (2)
78 を使ってオープンできる
79 .RB ( mkfifo (3)
80 を使って作成される)。
81 どんなプロセスでも、ファイルのアクセス許可があれば FIFO をオープンする
82 ことができる。
83 .\"O The read end is opened using the
84 .\"O .B O_RDONLY
85 .\"O flag; the write end is opened using the
86 .\"O .B O_WRONLY
87 .\"O flag.
88 .\"O See
89 .\"O .BR fifo (7)
90 .\"O for further details.
91 読み出し側をオープンするには
92 .B O_RDONLY
93 フラグを使用し、書き込み側をオープンするには
94 .B O_WRONLY
95 フラグを使用する。詳細は
96 .BR fifo (7)
97 を参照。
98 .\"O .IR Note :
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).
102 【注意】
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 に対する入出力は
114 全く同じ仕組みで行われる。
115
116 .\"O If a process attempts to read from an empty pipe, then
117 .\"O .BR read (2)
118 .\"O will block until data is available.
119 .\"O If a process attempts to write to a full pipe (see below), then
120 .\"O .BR write (2)
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
124 .\"O .BR fcntl (2)
125 .\"O .B F_SETFL
126 .\"O operation to enable the
127 .\"O .B O_NONBLOCK
128 .\"O open file status flag.
129 プロセスが空のパイプから読み出しを行おうとした場合、
130 .BR read (2)
131 はデータが読み出し可能になるまで停止する。
132 プロセスがフル状態のパイプに書き込みを行おうとした場合、
133 .BR write (2)
134 は書き込みを完了するのに十分な量のパイプからの読み出しが
135 行われるまで停止する。
136 非停止 (nonblocking) I/O を使うこともできる。
137 非停止 I/O を使うには、
138 .BR fcntl (2)
139 .B F_SETFL
140 操作を使って、
141 .B O_NONBLOCK
142 オープンファイル状態フラグを有効にする。
143
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 パイプにより提供される通信チャネルは「バイトストリーム」であり、
148 メッセージ境界の概念はない。
149
150 .\"O If all file descriptors referring to the write end of a pipe
151 .\"O have been closed, then an attempt to
152 .\"O .BR read (2)
153 .\"O from the pipe will see end-of-file
154 .\"O .RB ( read (2)
155 .\"O will return 0).
156 パイプの書き込み側を参照しているファイル・ディスクリプタが
157 すべてクローズされた後で、そのパイプから
158 .BR read (2)
159 を行おうとした場合、
160 end-of-file (ファイル末尾) が見える
161 .RB ( read (2)
162 は 0 を返す)。
163 .\"O If all file descriptors referring to the read end of a pipe
164 .\"O have been closed, then a
165 .\"O .BR write (2)
166 .\"O will cause a
167 .\"O .B SIGPIPE
168 .\"O signal to be generated for the calling process.
169 パイプの読み出し側を参照しているファイル・ディスクリプタが
170 すべてクローズされた後で、
171 .BR write (2)
172 を行うと、呼び出し元プロセスに
173 .B SIGPIPE
174 シグナルが送られる。
175 .\"O If the calling process is ignoring this signal, then
176 .\"O .BR write (2)
177 .\"O fails with the error
178 .\"O .BR EPIPE .
179 呼び出し元プロセスがこのシグナルを無視しているときには、
180 .BR write (2)
181 はエラー
182 .B EPIPE
183 で失敗する。
184 .\"O An application that uses
185 .\"O .BR pipe (2)
186 .\"O and
187 .\"O .BR fork (2)
188 .\"O should use suitable
189 .\"O .BR close (2)
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.
194 .BR pipe (2)
195
196 .BR fork (2)
197 を使用するアプリケーションでは、
198 .BR close (2)
199 を適切に使って不必要なファイル・ディスクリプタの複製を
200 クローズすべきである。こうすることで、必要な時に確実に
201 end-of-file や
202 .BR SIGPIPE / EPIPE
203 が配送されるようになる。
204
205 .\"O It is not possible to apply
206 .\"O .BR lseek (2)
207 .\"O to a pipe.
208 パイプには
209 .BR lseek (2)
210 を行うことはできない。
211 .\"O .SS "Pipe Capacity"
212 .SS パイプの容量
213 .\"O A pipe has a limited capacity.
214 .\"O If the pipe is full, then a
215 .\"O .BR write (2)
216 .\"O will block or fail, depending on whether the
217 .\"O .B O_NONBLOCK
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.
224 パイプの容量には上限がある。
225 パイプがフルの場合、
226 .BR write (2)
227 は停止したり失敗したりする。どちらになるかは
228 .B O_NONBLOCK
229 フラグがセットされているかどうかに依存する (下記参照)。
230 実装により、パイプの容量の上限は異なる。
231 アプリケーションは特定の容量を前提にすべきではない。
232 書き込み側のプロセスが停止したままにならないよう、
233 読み出し側のプロセスはデータが利用可能になったらできるだけすぐに
234 読み出しを行うように、アプリケーションを設計すべきである。
235
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 バイトである。
242 .\"O .SS PIPE_BUF
243 .SS PIPE_BUF
244 .\"O POSIX.1-2001 says that
245 .\"O .BR write (2)s
246 .\"O of less than
247 .\"O .B PIPE_BUF
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
251 .\"O .B PIPE_BUF
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
255 .\"O .B PIPE_BUF
256 .\"O to be at least 512 bytes.
257 .\"O (On Linux,
258 .\"O .B PIPE_BUF
259 .\"O is 4096 bytes.)
260 POSIX.1-2001 では、
261 .B PIPE_BUF
262 バイト以下の
263 .BR write (2)
264 は atomic に行われること、つまりパイプへの出力データの書き込みは
265 連続したシーケンスとして行われることを必須としている (MUST)。
266 .B PIPE_BUF
267 バイトより多くのデータを書き込み場合は atomic とはならない、
268 つまりパイプへの他のプロセスによるデータの書き込みが間に入る
269 可能性がある。
270 POSIX.1-2001 の仕様では、
271 .B PIPE_BUF
272 は最小でも 512 バイトであることが要求されている
273 (Linux では
274 .B PIPE_BUF
275 は 4096 バイトである)。
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
279 .\"O .IR n ,
280 .\"O the number of bytes to be written:
281 正確な動作は、ファイル・ディスクリプタが nonblocking
282 .RB ( O_NONBLOCK )
283 かどうか、パイプへの書き込みが複数から行われるかどうか、および
284 書き込みを行うバイト数
285 .I n
286 により決定される。
287 .TP
288 .\"O \fBO_NONBLOCK\fP disabled, \fIn\fP <= \fBPIPE_BUF\fP
289 \fBO_NONBLOCK\fP 無効, \fIn\fP <= \fBPIPE_BUF\fP
290 .\"O All
291 .\"O .I n
292 .\"O bytes are written atomically;
293 .\"O .BR write (2)
294 .\"O may block if there is not room for
295 .\"O .I n
296 .\"O bytes to be written immediately
297 .I n
298 バイト全部の書き込みが atomic に行われる。
299 .I n
300 バイト分をすぐに書き込む余地がない場合は
301 .BR write (2)
302 は停止 (block) することがある。
303 .TP
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
307 .\"O .I n
308 .\"O bytes to the pipe, then
309 .\"O .BR write (2)
310 .\"O succeeds immediately, writing all
311 .\"O .I n
312 .\"O bytes; otherwise
313 .\"O .BR write (2)
314 .\"O fails, with
315 .\"O .I errno
316 .\"O set to
317 .\"O .BR EAGAIN .
318 パイプに
319 .I n
320 バイトを書き込む余地がある場合は、
321 .I n
322 バイト全部がすぐに書き込まれる。
323 余地がない場合は、
324 .BR write (2)
325 は失敗し、
326 .I errno
327
328 .B EAGAIN
329 がセットされる。
330 .TP
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
334 .\"O .BR write (2)
335 .\"O may be interleaved with
336 .\"O .BR write (2)s
337 .\"O by other process;
338 .\"O the
339 .\"O .BR write (2)
340 .\"O blocks until
341 .\"O .I n
342 .\"O bytes have been written.
343 書き込みは atomic とはならない。
344 .BR write (2)
345 に渡されたデータの間に、他のプロセスにより
346 .BR write (2)
347 されたデータが入ることがある。
348 .BR write (2)
349
350 .I n
351 バイトの書き込みが完了するまで停止する。
352 .TP
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
356 .\"O .BR write (2)
357 .\"O fails, with
358 .\"O .I errno
359 .\"O set to
360 .\"O .BR EAGAIN .
361 .\"O Otherwise, from 1 to
362 .\"O .I n
363 .\"O bytes may be written (i.e., a "partial write" may occur;
364 .\"O the caller should check the return value from
365 .\"O .BR write (2)
366 .\"O to see how many bytes were actually written),
367 .\"O and these bytes may be interleaved with writes by other processes.
368 パイプがフルの場合、
369 .BR write (2)
370 は失敗し、
371 .I errno
372
373 .B EAGAIN
374 がセットされる。
375 それ以外の場合、1 バイト以上
376 .I n
377 バイト以下のデータが書き込まれる
378 (つまり「一部分だけ書き込まれる」場合もあり得る)。
379 呼び出し元は
380 .BR write (2)
381 の返り値を参照し、実際に何バイト書き込まれたのかを確認すべきである。
382 また、書き込みに成功したデータも、他のプロセスが書き込んだデータが
383 間に入ることがある。
384 .\"O .SS "Open File Status Flags"
385 .SS オープンファイル状態フラグ
386 .\"O The only open file status flags that can be meaningfully applied to
387 .\"O a pipe or FIFO are
388 .\"O .B O_NONBLOCK
389 .\"O and
390 .\"O .BR O_ASYNC .
391 オープンファイル状態フラグのうち、パイプや FIFO に対して意味を持つのは
392 .B O_NONBLOCK
393
394 .B O_ASYNC
395 だけである。
396
397 .\"O Setting the
398 .\"O .B O_ASYNC
399 .\"O flag for the read end of a pipe causes a signal
400 .\"O .RB ( SIGIO
401 .\"O by default) to be generated when new input becomes available on the pipe
402 .\"O (see
403 .\"O .BR fcntl (2)
404 .\"O for details).
405 .\"O On Linux,
406 .\"O .B O_ASYNC
407 .\"O is supported for pipes and FIFOs only since kernel 2.6.
408 パイプの読み出し側に
409 .B O_ASYNC
410 フラグをセットすると、パイプに新たな入力があるとシグナル (デフォルトでは
411 .BR SIGIO )
412 が生成される (詳細は
413 .BR fcntl (2)
414 を参照)。
415 Linux では、
416 パイプと FIFO に対する
417 .B O_ASYNC
418 はカーネル 2.6 以降でのみサポートされている。
419 .\"O .SS "Portability notes"
420 .SS 移植に関する注意
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 移植を考慮したアプリケーションでは、双方向パイプの仕組みを
430 前提にすべきではない。
431 .\"O .SH "SEE ALSO"
432 .SH 関連項目
433 .BR dup (2),
434 .BR fcntl (2),
435 .BR open (2),
436 .BR pipe (2),
437 .BR poll (2),
438 .BR select (2),
439 .BR socketpair (2),
440 .BR stat (2),
441 .BR mkfifo (3),
442 .BR epoll (7),
443 .BR fifo (7)