OSDN Git Service

eb2eef2dcd48d79f18319572d600b94d657d2db4
[linuxjm/LDP_man-pages.git] / release / man2 / dup.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" and Copyright (C) 1993 Michael Haardt, Ian Jackson.
5 .\" and Copyright (C) 2005, 2008 Michael Kerrisk <mtk.manpages@gmail.com>
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 1993-07-21, Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1994-08-21, Michael Chastain <mec@shell.portal.com>:
29 .\"   Fixed typoes.
30 .\" Modified 1997-01-31, Eric S. Raymond <esr@thyrsus.com>
31 .\" Modified 2002-09-28, aeb
32 .\" 2009-01-12, mtk, reordered text in DESCRIPTION and added some
33 .\"     details for dup2().
34 .\" 2008-10-09, mtk: add description of dup3()
35 .\"
36 .\" Japanese Version Copyright (c) 1996 Takeshi Ueno
37 .\"         all rights reserved.
38 .\" Translated 1996-07-03, Takeshi Ueno <tueno@vio.co.jp>
39 .\" Modified 1997-12-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
40 .\" Modified 2003-01-16, Akihiro Motoki <amotoki@dd.iij4u.or.jp>
41 .\" Updated & Modified 2004-05-19, Yuichi SATO <ysato444@yahoo.co.jp>
42 .\" Updated & Modified 2005-09-07 Akihiro MOTOKI
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 DUP 2 2010-09-10 "Linux" "Linux Programmer's Manual"
47 .SH Ì¾Á°
48 dup, dup2, dup3 \- ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊ£À½¤¹¤ë
49 .SH ½ñ¼°
50 .nf
51 .B #include <unistd.h>
52 .sp
53 .BI "int dup(int " oldfd );
54 .BI "int dup2(int " oldfd ", int " newfd );
55 .sp
56 .BR "#define _GNU_SOURCE" "             /* feature_test_macros(7) »²¾È */"
57 .B #include <unistd.h>
58 .sp
59 .BI "int dup3(int " oldfd ", int " newfd ", int " flags );
60 .fi
61 .SH ÀâÌÀ
62 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
63 .I oldfd
64 ¤ÎÊ£À½¤òºî¤ë¡£
65
66 .BR dup ()
67 ¤ÏºÇ¤â¾®¤µ¤¤ÈÖ¹æ¤Î̤»ÈÍѤΥǥ£¥¹¥¯¥ê¥×¥¿¤ò
68 ¿·¤·¤¤¥Ç¥£¥¹¥¯¥ê¥×¥¿¤È¤·¤Æ»ÈÍѤ¹¤ë¡£
69
70 .BR dup2 ()
71 ¤Ï
72 .I newfd
73 ¤ò
74 .I oldfd
75 ¤ÎÊ£À½¤È¤·¤ÆºîÀ®¤¹¤ë¡£
76 ɬÍפǤ¢¤ì¤ÐºÇ½é¤Ë
77 .I newfd
78 ¤ò¥¯¥í¡¼¥º¤¹¤ë¡£
79 °Ê²¼¤ÎÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È¡£
80 .IP * 3
81 .I oldfd
82 ¤¬Í­¸ú¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¾ì¹ç¡¢¤½¤Î¸Æ¤Ó½Ð¤·¤Ï¼ºÇÔ¤·¡¢
83 .I newfd
84 ¤Ï¥¯¥í¡¼¥º¤µ¤ì¤Ê¤¤¡£
85 .IP *
86 .I oldfd
87 ¤¬Í­¸ú¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¡¢
88 .I newfd
89 ¤¬
90 .I oldfd
91 ¤ÈƱ¤¸Ãͤξì¹ç¡¢
92 .BR dup2 ()
93 ¤Ï²¿¤â¤»¤º¡¢
94 .I newfd
95 ¤òÊÖ¤¹¡£
96 .PP
97 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î¤¤¤º¤ì¤«¤¬À®¸ù¤òÊÖ¤·¤¿¾ì¹ç¤Ë¤Ï¡¢
98 ¸Å¤¤¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤È¿·¤·¤¤¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï
99 ¸ß¤¤¤Ë²Ä´¹¤Ê¤â¤Î¤È¤·¤Æ»È¤¦¤³¤È¤¬¤Ç¤­¤ë¡£
100 2¤Ä¤Î¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÏƱ¤¸¥Õ¥¡¥¤¥ëµ­½Ò (description)
101 .RB ( open (2)
102 »²¾È) ¤ò»²¾È¤·¤Æ¤ª¤ê¡¢¤·¤¿¤¬¤Ã¤Æ¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤ä¥Õ¥¡¥¤¥ë¾õÂ֥ե饰¤¬
103 ¶¦Í­¤µ¤ì¤ë¡£Î㤨¤Ð¡¢°ìÊý¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ·¤Æ
104 .BR lseek (2)
105 ¤ò»È¤Ã¤Æ¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤òÊѹ¹¤·¤¿¾ì¹ç¡¢¤â¤¦°ìÊý¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î
106 ¥ª¥Õ¥»¥Ã¥È¤âÊѲ½¤¹¤ë¡£
107
108 2¤Ä¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¦¥Õ¥é¥° (close-on-exec flag)
109 ¤ò¶¦Í­¤·¤Ê¤¤¡£Ê£À½¤µ¤ì¤¿¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î
110 close-on-exec flag
111 .RB ( fcntl (2)
112 »²¾È) ¤Ï off ¤È¤Ê¤ë¡£
113
114 .BR dup3 ()
115 ¤Ï
116 .BR dup2 ()
117 ¤ÈƱ¤¸¤À¤¬¡¢°Ê²¼¤ÎÅÀ¤¬°Û¤Ê¤ë¡£
118 .IP * 3
119 ¸Æ¤Ó½Ð¤·¸µ¤¬¡¢¿·¤·¤¤¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ·¤Æ
120 close-on-exec ¥Õ¥é¥°¤ò¶¯À©Åª¤ËÀßÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
121 ¤³¤ì¤ò¹Ô¤¦¤Ë¤Ï¡¢
122 .I flags
123 ¤Ë
124 .B O_CLOEXEC
125 ¤ò»ØÄꤹ¤ë¡£
126 ¤³¤Î¥Õ¥é¥°¤¬Ìò¤ËΩ¤ÄÍýͳ¤Ë¤Ä¤¤¤Æ¤Ï¡¢
127 .BR open (2)
128 ¤Î
129 .B O_CLOEXEC
130 ¥Õ¥é¥°¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
131 .IP *
132 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
133 .I oldfd
134 ¤¬
135 .I newfd
136 ¤ÈƱ¤¸¾ì¹ç¡¢
137 .BR dup3 ()
138 ¤Ï
139 .B EINVAL
140 ¥¨¥é¡¼¤Ç¼ºÇÔ¤¹¤ë¡£
141 .SH ÊÖ¤êÃÍ
142 À®¸ù¤¹¤ë¤È¡¢¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¿·¤·¤¤¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
143 ¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤òÊÖ¤·¡¢
144 .I errno
145 ¤òŬÀÚ¤ËÀßÄꤹ¤ë¡£
146 .SH ¥¨¥é¡¼
147 .TP
148 .B EBADF
149 .I oldfd
150 ¤¬¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¤«¡¢
151 .I newfd
152 ¤¬¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤È¤·¤Æµö¤µ¤ì¤ëÈϰϤ«¤é³°¤ì¤Æ¤¤¤ë¡£
153 .TP
154 .B EBUSY
155 (Linux ¤Î¤ß)
156 .BR open (2)
157 ¤ä
158 .BR dup ()
159 ¤È¤Î¶¥¹ç¾õÂ֤ξì¹ç¤Ë¡¢
160 .BR dup2 ()
161 ¤ä
162 .BR dup3 ()
163 ¤Ï¤³¤Î¥¨¥é¡¼¤òÊÖ¤¹¤«¤â¤·¤ì¤Ê¤¤¡£
164 .TP
165 .B EINTR
166 .BR dup2 ()
167 ¤ä
168 .BR dup3 ()
169 ¤Î¸Æ¤Ó½Ð¤·¤¬¥·¥°¥Ê¥ë¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¡£
170 .BR signal (7)
171 »²¾È¡£
172 .TP
173 .B EINVAL
174 .RB ( dup3 ())
175 .I flags
176 ¤Ë̵¸ú¤ÊÃͤ¬Æþ¤Ã¤Æ¤¤¤ë¡£
177 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
178 ¤â¤·¤¯¤Ï¡¢
179 .I oldfd
180 ¤¬
181 .I newfd
182 ¤ÈƱ¤¸¤Ç¤¢¤Ã¤¿¡£
183 .TP
184 .B EMFILE
185 ¥×¥í¥»¥¹¤¬¤¹¤Ç¤Ë¥ª¡¼¥×¥ó¤Ç¤­¤ëºÇÂç¿ô¤Þ¤Ç¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
186 ¤ò³«¤¤¤Æ¤¤¤Æ¡¢¤µ¤é¤Ë¿·¤·¤¤¤â¤Î¤ò³«¤³¤¦¤È¤·¤¿¡£
187 .SH ¥Ð¡¼¥¸¥ç¥ó
188 .BR dup3 ()
189 ¤Ï¥Ð¡¼¥¸¥ç¥ó 2.6.27 ¤Ç Linux ¤ËÄɲ䵤줿¡£
190 glibc ¤Ë¤è¤ë¥µ¥Ý¡¼¥È¤Ï¥Ð¡¼¥¸¥ç¥ó 2.9 °Ê¹ß¤ÇÍøÍѤǤ­¤ë¡£
191 .SH ½àµò
192 .BR dup (),
193 .BR dup2 ():
194 SVr4, 4.3BSD, POSIX.1-2001.
195
196 .BR dup3 ()
197 ¤Ï Linux ¸ÇÍ­¤Ç¤¢¤ë¡£
198 .\" SVr4 ¤Ë¤Ï¾¤Ë EINTR, ENOLINK ¥¨¥é¡¼¾õÂ֤ε­½Ò¤¬¤¢¤ë¡£
199 .\" POSIX.1 ¤Ë¤Ï¾¤Ë EINTR ¤¬¤¢¤ë¡£
200 .\" EBUSY ¤¬ÊÖ¤µ¤ì¤ë¤Î¤Ï Linux Æȼ«¤Î¤â¤Î¤Ç¤¢¤ë¡£
201 .SH Ãí°Õ
202 .I newfd
203 ¤¬ÈϰϤòĶ¤¨¤¿»þ¤ËÊÖ¤µ¤ì¤ë¥¨¥é¡¼¤Ï¡¢
204 .BR dup2 ()
205 ¤È
206 .BR fcntl( "..., " F_DUPFD ", ..." )
207 ¤Ç¤Ï°Û¤Ã¤Æ¤¤¤ë¡£
208 .BR dup2 ()
209 ¤¬
210 .B F_DUPFD
211 ¤ÈƱ¤¸¤è¤¦¤Ë
212 .B EINVAL
213 ¤òÊÖ¤¹¥·¥¹¥Æ¥à¤â¤¢¤ë¡£
214
215 .I newfd
216 ¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¤È¡¢
217 .BR close (2)
218 ¤·¤¿»þ¤ËÊó¹ð¤µ¤ì¤ë¤Ï¤º¤Î¥¨¥é¡¼¤¬¼º¤ï¤ì¤Æ¤·¤Þ¤¦¡£
219 .BR dup2 ()
220 ¤ä
221 .BR dup3 ()
222 ¤ò»È¤¦Á°¤ËÀ褺
223 .I newfd
224 ¤ò¥¯¥í¡¼¥º¤¹¤ë¤è¤¦¤Ë¤·¤¿Êý¤¬¤¤¤¤¤À¤í¤¦¡£
225 .SH ´ØÏ¢¹àÌÜ
226 .BR close (2),
227 .BR fcntl (2),
228 .BR open (2)