1 .\" Hey Emacs! This file is -*- nroff -*- source.
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>.)
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.
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.
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
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
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
34 .\" 2008-10-10, mtk: add description of pipe2()
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
46 .TH PIPE 2 2010-09-10 "Linux" "Linux Programmer's Manual"
48 pipe, pipe2 \- ¥Ñ¥¤¥×¤òÀ¸À®¤¹¤ë
51 .B #include <unistd.h>
53 .BI "int pipe(int " pipefd "[2]);"
55 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) »²¾È */"
56 .B #include <unistd.h>
58 .BI "int pipe2(int " pipefd "[2], int " flags );
63 ¥Ñ¥¤¥×¤Ï¡¢¥×¥í¥»¥¹´ÖÄÌ¿®¤Ë»ÈÍѤǤ¤ëñÊý¸þ¤Î¥Ç¡¼¥¿¥Á¥ã¥Í¥ë¤Ç¤¢¤ë¡£
66 ¤Ï¡¢¥Ñ¥¤¥×¤Îξü¤ò»²¾È¤¹¤ëÆó¤Ä¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò
69 ¤¬¥Ñ¥¤¥×¤ÎÆɤ߽Ф·Â¦¡¢
71 ¤¬¥Ñ¥¤¥×¤Î½ñ¤¹þ¤ß¦¤Ç¤¢¤ë¡£
72 ¥Ñ¥¤¥×¤Î½ñ¤¹þ¤ß¦¤Ë½ñ¤¹þ¤Þ¤ì¤¿¥Ç¡¼¥¿¤Ï¡¢
73 ¥Ñ¥¤¥×¤ÎÆɤ߽Ф·Â¦¤«¤éÆɤ߽Фµ¤ì¤ë¤Þ¤Ç¥«¡¼¥Í¥ë¤Ç¥Ð¥Ã¥Õ¥¡¥ê¥ó¥°¤µ¤ì¤ë¡£
85 ¤Ë°Ê²¼¤ÎÃͤò¥Ó¥Ã¥ÈËè¤ÎÏÀÍýÏ (OR) ¤Ç»ØÄꤹ¤ë¤³¤È¤Ç¡¢
86 °Û¤Ê¤ëÆ°ºî¤ò¤µ¤»¤ë¤³¤È¤¬¤Ç¤¤ë¡£
89 ¿·¤·¤¯À¸À®¤µ¤ì¤ëÆó¤Ä¤Î¥ª¡¼¥×¥ó¥Õ¥¡¥¤¥ëµ½Ò (open file description) ¤Î
91 ¥Õ¥¡¥¤¥ë¥¹¥Æ¡¼¥¿¥¹¥Õ¥é¥°¤ò¥»¥Ã¥È¤¹¤ë¡£
92 ¤³¤Î¥Õ¥é¥°¤ò»È¤¦¤³¤È¤Ç¡¢
96 ¤òÄɲäǸƤӽФ¹É¬Íפ¬¤Ê¤¯¤Ê¤ë¡£
99 ¿·¤·¤¯À¸À®¤µ¤ì¤ëÆó¤Ä¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î
103 ¤³¤Î¥Õ¥é¥°¤¬Ìò¤ËΩ¤ÄÍýͳ¤Ë¤Ä¤¤¤Æ¤Ï¡¢
107 ¥Õ¥é¥°¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
109 À®¸ù¤·¤¿¾ì¹ç 0 ¤¬Ê֤롣¼ºÇÔ¤·¤¿¾ì¹ç \-1 ¤¬Ê֤ꡢ
111 ¤¬¥¨¥é¡¼¤ÎÆâÍƤ˽¾¤Ã¤ÆÀßÄꤵ¤ì¤ë¡£
121 ¤Ë̵¸ú¤ÊÃͤ¬Æþ¤Ã¤Æ¤¤¤ë¡£
124 ¤³¤Î¥×¥í¥»¥¹¤Ç»È¤ï¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬Â¿¤¹¤®¤ë¡£
127 ¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤ÎÁí¿ô¤¬¥·¥¹¥Æ¥à¤ÎÀ©¸Â¤Ë㤷¤¿¡£
130 ¤Ï¥Ð¡¼¥¸¥ç¥ó 2.6.27 ¤Ç Linux ¤ËÄɲ䵤줿¡£
131 glibc ¤Ë¤è¤ë¥µ¥Ý¡¼¥È¤Ï¥Ð¡¼¥¸¥ç¥ó 2.9 °Ê¹ß¤ÇÍøÍѤǤ¤ë¡£
137 ¤Ï Linux ¸ÇͤǤ¢¤ë¡£
139 .\" fork.2 ¤Ï¤³¤ÎÎã¤Î¥×¥í¥°¥é¥à¤ò»²¾È¤·¤Æ¤¤¤ë¡£
140 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ç¤Ï¥Ñ¥¤¥×¤òÀ¸À®¤·¡¢¤½¤Î¸å
142 ¤Ç»Ò¥×¥í¥»¥¹¤òÀ¸À®¤¹¤ë¡£
143 »Ò¥×¥í¥»¥¹¤ÏƱ¤¸¥Ñ¥¤¥×¤ò»²¾È¤¹¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿½¸¹ç¤Î¥³¥Ô¡¼¤ò
146 ¤Î¸å¡¢³Æ¥×¥í¥»¥¹¤Ï¥Ñ¥¤¥×
148 ¤ò»²¾È) ¤ËɬÍפ¬¤Ê¤¯¤Ê¤Ã¤¿¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ò¥¯¥í¡¼¥º¤¹¤ë¡£
149 ¿Æ¥×¥í¥»¥¹¤Ï¥×¥í¥°¥é¥à¤Î¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¤¿ô¤Ë´Þ¤Þ¤ì¤ë
150 ʸ»úÎó¤ò¥Ñ¥¤¥×¤Ø½ñ¤¹þ¤ß¡¢
151 »Ò¥×¥í¥»¥¹¤Ï¤³¤Îʸ»úÎó¤ò¥Ñ¥¤¥×¤«¤é 1 ¥Ð¥¤¥È¤º¤ÄÆɤ߹þ¤ó¤Çɸ½à½ÐÎϤ˥¨¥³¡¼¤¹¤ë¡£
154 #include <sys/wait.h>
161 main(int argc, char *argv[])
168 fprintf(stderr, "Usage: %s <string>\\n", argv[0]);
172 if (pipe(pipefd) == \-1) {
183 if (cpid == 0) { /* »Ò¥×¥í¥»¥¹¤¬¥Ñ¥¤¥×¤«¤éÆɤ߹þ¤à */
184 close(pipefd[1]); /* »ÈÍѤ·¤Ê¤¤ write ¦¤Ï¥¯¥í¡¼¥º¤¹¤ë */
186 while (read(pipefd[0], &buf, 1) > 0)
187 write(STDOUT_FILENO, &buf, 1);
189 write(STDOUT_FILENO, "\\n", 1);
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); /* »Ò¥×¥í¥»¥¹¤òÂÔ¤Ä */