OSDN Git Service

(split) LDP v3.24 -> v3.29 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / release / man2 / pipe.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (C) 2005, 2008, Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" (A few fragments remain from an earlier (1992) version by
5 .\" Drew Eckhardt <drew@cs.colorado.edu>.)
6 .\"
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein.  The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"
27 .\" Modified by Michael Haardt <michael@moria.de>
28 .\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
29 .\" Modified 1996-10-22 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 2004-06-17 by Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Modified 2005, mtk: added an example program
32 .\" Modified 2008-01-09, mtk: rewrote DESCRIPTION; minor additions
33 .\"     to EXAMPLE text.
34 .\" 2008-10-10, mtk: add description of pipe2()
35 .\"
36 .\" Japanese Version Copyright (c) 1997 SUTO, Mitsuaki
37 .\"         all rights reserved.
38 .\" Translated Thu Jun 26 21:09:51 JST 1997
39 .\"         by SUTO, Mitsuaki <suto@av.crl.sony.co.jp>
40 .\" Updated & Modified Thu Feb 10 00:47:11 JST 2005
41 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>
42 .\" Updated & Modified Sat Dec 17 08:10:16 JST 2005 by Yuichi SATO
43 .\" Updated 2008-02-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
44 .\" Updated 2008-11-09, Akihiro MOTOKI, LDP v3.13
45 .\"
46 .TH PIPE 2 2010-09-10 "Linux" "Linux Programmer's Manual"
47 .SH Ì¾Á°
48 pipe, pipe2 \- ¥Ñ¥¤¥×¤òÀ¸À®¤¹¤ë
49 .SH ½ñ¼°
50 .nf
51 .B #include <unistd.h>
52 .sp
53 .BI "int pipe(int " pipefd "[2]);"
54 .sp
55 .BR "#define _GNU_SOURCE" "             /* feature_test_macros(7) »²¾È */"
56 .B #include <unistd.h>
57 .sp
58 .BI "int pipe2(int " pipefd "[2], int " flags );
59 .fi
60 .SH ÀâÌÀ
61 .BR pipe (2)
62 ¤Ï¥Ñ¥¤¥×¤òÀ¸À®¤¹¤ë¡£
63 ¥Ñ¥¤¥×¤Ï¡¢¥×¥í¥»¥¹´ÖÄÌ¿®¤Ë»ÈÍѤǤ­¤ëñÊý¸þ¤Î¥Ç¡¼¥¿¥Á¥ã¥Í¥ë¤Ç¤¢¤ë¡£
64 ÇÛÎó
65 .I pipefd
66 ¤Ï¡¢¥Ñ¥¤¥×¤Îξü¤ò»²¾È¤¹¤ëÆó¤Ä¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò
67 ÊÖ¤¹¤Î¤Ë»ÈÍѤµ¤ì¤ë¡£
68 .I pipefd[0]
69 ¤¬¥Ñ¥¤¥×¤ÎÆɤ߽Ф·Â¦¡¢
70 .I pipefd[1]
71 ¤¬¥Ñ¥¤¥×¤Î½ñ¤­¹þ¤ß¦¤Ç¤¢¤ë¡£
72 ¥Ñ¥¤¥×¤Î½ñ¤­¹þ¤ß¦¤Ë½ñ¤­¹þ¤Þ¤ì¤¿¥Ç¡¼¥¿¤Ï¡¢
73 ¥Ñ¥¤¥×¤ÎÆɤ߽Ф·Â¦¤«¤éÆɤ߽Фµ¤ì¤ë¤Þ¤Ç¥«¡¼¥Í¥ë¤Ç¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤µ¤ì¤ë¡£
74 ¤µ¤é¤Ê¤ë¾ÜºÙ¤Ï
75 .BR pipe (7)
76 ¤ò»²¾È¤Î¤³¤È¡£
77
78 .BR pipe2 ()
79 ¤Ï
80 .I flags
81 ¤¬ 0 ¤Î¾ì¹ç¤Ë¤Ï
82 .BR pipe ()
83 ¤ÈƱ¤¸¤Ç¤¢¤ë¡£
84 .I flags
85 ¤Ë°Ê²¼¤ÎÃͤò¥Ó¥Ã¥ÈËè¤ÎÏÀÍýÏ (OR) ¤Ç»ØÄꤹ¤ë¤³¤È¤Ç¡¢
86 °Û¤Ê¤ëÆ°ºî¤ò¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
87 .TP 12
88 .B O_NONBLOCK
89 ¿·¤·¤¯À¸À®¤µ¤ì¤ëÆó¤Ä¤Î¥ª¡¼¥×¥ó¥Õ¥¡¥¤¥ëµ­½Ò (open file description) ¤Î
90 .B O_NONBLOCK
91 ¥Õ¥¡¥¤¥ë¥¹¥Æ¡¼¥¿¥¹¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë¡£
92 ¤³¤Î¥Õ¥é¥°¤ò»È¤¦¤³¤È¤Ç¡¢
93 .B O_NONBLOCK
94 ¤ò¥»¥Ã¥È¤¹¤ë¤¿¤á¤Ë
95 .BR fcntl (2)
96 ¤òÄɲäǸƤӽФ¹É¬Íפ¬¤Ê¤¯¤Ê¤ë¡£
97 .TP
98 .B O_CLOEXEC
99 ¿·¤·¤¯À¸À®¤µ¤ì¤ëÆó¤Ä¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î
100 close-on-exec
101 .RB ( FD_CLOEXEC )
102 ¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë¡£
103 ¤³¤Î¥Õ¥é¥°¤¬Ìò¤ËΩ¤ÄÍýͳ¤Ë¤Ä¤¤¤Æ¤Ï¡¢
104 .BR open (2)
105 ¤Î
106 .B O_CLOEXEC
107 ¥Õ¥é¥°¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
108 .SH ÊÖ¤êÃÍ
109 À®¸ù¤·¤¿¾ì¹ç 0 ¤¬Ê֤롣¼ºÇÔ¤·¤¿¾ì¹ç \-1 ¤¬Ê֤ꡢ
110 .I errno
111 ¤¬¥¨¥é¡¼¤ÎÆâÍƤ˽¾¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£
112 .SH ¥¨¥é¡¼
113 .TP
114 .B EFAULT
115 .I pipefd
116 ¤¬Ìµ¸ú¤ÊÃͤǤ¢¤ë¡£
117 .TP
118 .B EINVAL
119 .RB ( pipe2 ())
120 .I flags
121 ¤Ë̵¸ú¤ÊÃͤ¬Æþ¤Ã¤Æ¤¤¤ë¡£
122 .TP
123 .B EMFILE
124 ¤³¤Î¥×¥í¥»¥¹¤Ç»È¤ï¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬Â¿¤¹¤®¤ë¡£
125 .TP
126 .B ENFILE
127 ¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤ÎÁí¿ô¤¬¥·¥¹¥Æ¥à¤ÎÀ©¸Â¤Ë㤷¤¿¡£
128 .SH ¥Ð¡¼¥¸¥ç¥ó
129 .BR pipe2 ()
130 ¤Ï¥Ð¡¼¥¸¥ç¥ó 2.6.27 ¤Ç Linux ¤ËÄɲ䵤줿¡£
131 glibc ¤Ë¤è¤ë¥µ¥Ý¡¼¥È¤Ï¥Ð¡¼¥¸¥ç¥ó 2.9 °Ê¹ß¤ÇÍøÍѤǤ­¤ë¡£
132 .SH ½àµò
133 .BR pipe ():
134 POSIX.1-2001.
135
136 .BR pipe2 ()
137 ¤Ï Linux ¸ÇÍ­¤Ç¤¢¤ë¡£
138 .SH Îã
139 .\" fork.2 ¤Ï¤³¤ÎÎã¤Î¥×¥í¥°¥é¥à¤ò»²¾È¤·¤Æ¤¤¤ë¡£
140 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ç¤Ï¥Ñ¥¤¥×¤òÀ¸À®¤·¡¢¤½¤Î¸å
141 .BR fork (2)
142 ¤Ç»Ò¥×¥í¥»¥¹¤òÀ¸À®¤¹¤ë¡£
143 »Ò¥×¥í¥»¥¹¤ÏƱ¤¸¥Ñ¥¤¥×¤ò»²¾È¤¹¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿½¸¹ç¤Î¥³¥Ô¡¼¤ò
144 ·Ñ¾µ¤¹¤ë¡£
145 .BR fork (2)
146 ¤Î¸å¡¢³Æ¥×¥í¥»¥¹¤Ï¥Ñ¥¤¥×
147 .RB ( pipe (7)
148 ¤ò»²¾È) ¤ËɬÍפ¬¤Ê¤¯¤Ê¤Ã¤¿¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò¥¯¥í¡¼¥º¤¹¤ë¡£
149 ¿Æ¥×¥í¥»¥¹¤Ï¥×¥í¥°¥é¥à¤Î¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ë´Þ¤Þ¤ì¤ë
150 ʸ»úÎó¤ò¥Ñ¥¤¥×¤Ø½ñ¤­¹þ¤ß¡¢
151 »Ò¥×¥í¥»¥¹¤Ï¤³¤Îʸ»úÎó¤ò¥Ñ¥¤¥×¤«¤é 1 ¥Ð¥¤¥È¤º¤ÄÆɤ߹þ¤ó¤Çɸ½à½ÐÎϤ˥¨¥³¡¼¤¹¤ë¡£
152 .nf
153
154 #include <sys/wait.h>
155 #include <stdio.h>
156 #include <stdlib.h>
157 #include <unistd.h>
158 #include <string.h>
159
160 int
161 main(int argc, char *argv[])
162 {
163     int pipefd[2];
164     pid_t cpid;
165     char buf;
166
167     if (argc != 2) {
168         fprintf(stderr, "Usage: %s <string>\\n", argv[0]);
169         exit(EXIT_FAILURE);
170     }
171
172     if (pipe(pipefd) == \-1) {
173         perror("pipe");
174         exit(EXIT_FAILURE);
175     }
176
177     cpid = fork();
178     if (cpid == \-1) {
179         perror("fork");
180         exit(EXIT_FAILURE);
181     }
182
183     if (cpid == 0) {    /* »Ò¥×¥í¥»¥¹¤¬¥Ñ¥¤¥×¤«¤éÆɤ߹þ¤à */
184         close(pipefd[1]);  /* »ÈÍѤ·¤Ê¤¤ write Â¦¤Ï¥¯¥í¡¼¥º¤¹¤ë */
185
186         while (read(pipefd[0], &buf, 1) > 0)
187             write(STDOUT_FILENO, &buf, 1);
188
189         write(STDOUT_FILENO, "\\n", 1);
190         close(pipefd[0]);
191         _exit(EXIT_SUCCESS);
192
193     } else {            /* ¿Æ¥×¥í¥»¥¹¤Ï argv[1] ¤ò¥Ñ¥¤¥×¤Ø½ñ¤­¹þ¤à */
194         close(pipefd[0]);          /* »ÈÍѤ·¤Ê¤¤ read Â¦¤Ï¥¯¥í¡¼¥º¤¹¤ë */
195         write(pipefd[1], argv[1], strlen(argv[1]));
196         close(pipefd[1]);          /* Æɤ߹þ¤ß¦¤¬ EOF ¤Ë½Ð²ñ¤¦ */
197         wait(NULL);                /* »Ò¥×¥í¥»¥¹¤òÂԤĠ*/
198         exit(EXIT_SUCCESS);
199     }
200 }
201 .fi
202 .SH ´ØÏ¢¹àÌÜ
203 .BR fork (2),
204 .BR read (2),
205 .BR socketpair (2),
206 .BR write (2),
207 .BR popen (3),
208 .BR pipe (7)