OSDN Git Service

(split) Move Japanese translation histories after original history sections.
[linuxjm/LDP_man-pages.git] / draft / 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 .\"O .SH NAME
48 .\"O dup, dup2, dup3 \- duplicate a file descriptor
49 .SH Ì¾Á°
50 dup, dup2, dup3 \- ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊ£À½¤¹¤ë
51 .\"O .SH SYNOPSIS
52 .SH ½ñ¼°
53 .nf
54 .B #include <unistd.h>
55 .sp
56 .BI "int dup(int " oldfd );
57 .BI "int dup2(int " oldfd ", int " newfd );
58 .sp
59 .\"O .BR "#define _GNU_SOURCE" "             /* See feature_test_macros(7) */"
60 .BR "#define _GNU_SOURCE" "             /* feature_test_macros(7) »²¾È */"
61 .B #include <unistd.h>
62 .sp
63 .BI "int dup3(int " oldfd ", int " newfd ", int " flags );
64 .fi
65 .\"O .SH DESCRIPTION
66 .SH ÀâÌÀ
67 .\"O These system calls create a copy of the file descriptor
68 .\"O .IR oldfd .
69 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
70 .I oldfd
71 ¤ÎÊ£À½¤òºî¤ë¡£
72
73 .\"O .BR dup ()
74 .\"O uses the lowest-numbered unused descriptor for the new descriptor.
75 .BR dup ()
76 ¤ÏºÇ¤â¾®¤µ¤¤ÈÖ¹æ¤Î̤»ÈÍѤΥǥ£¥¹¥¯¥ê¥×¥¿¤ò
77 ¿·¤·¤¤¥Ç¥£¥¹¥¯¥ê¥×¥¿¤È¤·¤Æ»ÈÍѤ¹¤ë¡£
78
79 .\"O .BR dup2 ()
80 .\"O .RI "makes " newfd " be the copy of " oldfd ", closing " newfd
81 .\"O first if necessary, but note the following:
82 .BR dup2 ()
83 ¤Ï
84 .I newfd
85 ¤ò
86 .I oldfd
87 ¤ÎÊ£À½¤È¤·¤ÆºîÀ®¤¹¤ë¡£
88 ɬÍפǤ¢¤ì¤ÐºÇ½é¤Ë
89 .I newfd
90 ¤ò¥¯¥í¡¼¥º¤¹¤ë¡£
91 °Ê²¼¤ÎÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È¡£
92 .IP * 3
93 .\"O If
94 .\"O .I oldfd
95 .\"O is not a valid file descriptor, then the call fails, and
96 .\"O .I newfd
97 .\"O is not closed.
98 .I oldfd
99 ¤¬Í­¸ú¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¾ì¹ç¡¢¤½¤Î¸Æ¤Ó½Ð¤·¤Ï¼ºÇÔ¤·¡¢
100 .I newfd
101 ¤Ï¥¯¥í¡¼¥º¤µ¤ì¤Ê¤¤¡£
102 .IP *
103 .\"O If
104 .\"O .I oldfd
105 .\"O is a valid file descriptor, and
106 .\"O .I newfd
107 .\"O has the same value as
108 .\"O .IR oldfd ,
109 .\"O then
110 .\"O .BR dup2 ()
111 .\"O does nothing, and returns
112 .\"O .IR newfd .
113 .I oldfd
114 ¤¬Í­¸ú¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¡¢
115 .I newfd
116 ¤¬
117 .I oldfd
118 ¤ÈƱ¤¸Ãͤξì¹ç¡¢
119 .BR dup2 ()
120 ¤Ï²¿¤â¤»¤º¡¢
121 .I newfd
122 ¤òÊÖ¤¹¡£
123 .PP
124 .\"O After a successful return from one of these system calls,
125 .\"O the old and new file descriptors may be used interchangeably.
126 .\"O They refer to the same open file description (see
127 .\"O .BR open (2))
128 .\"O and thus share file offset and file status flags;
129 .\"O for example, if the file offset is modified by using
130 .\"O .BR lseek (2)
131 .\"O on one of the descriptors, the offset is also changed for the other.
132 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î¤¤¤º¤ì¤«¤¬À®¸ù¤òÊÖ¤·¤¿¾ì¹ç¤Ë¤Ï¡¢
133 ¸Å¤¤¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤È¿·¤·¤¤¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï
134 ¸ß¤¤¤Ë²Ä´¹¤Ê¤â¤Î¤È¤·¤Æ»È¤¦¤³¤È¤¬¤Ç¤­¤ë¡£
135 2¤Ä¤Î¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÏƱ¤¸¥Õ¥¡¥¤¥ëµ­½Ò (description)
136 .RB ( open (2)
137 »²¾È) ¤ò»²¾È¤·¤Æ¤ª¤ê¡¢¤·¤¿¤¬¤Ã¤Æ¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤ä¥Õ¥¡¥¤¥ë¾õÂ֥ե饰¤¬
138 ¶¦Í­¤µ¤ì¤ë¡£Î㤨¤Ð¡¢°ìÊý¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ·¤Æ
139 .BR lseek (2)
140 ¤ò»È¤Ã¤Æ¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤òÊѹ¹¤·¤¿¾ì¹ç¡¢¤â¤¦°ìÊý¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î
141 ¥ª¥Õ¥»¥Ã¥È¤âÊѲ½¤¹¤ë¡£
142
143 .\"O The two descriptors do not share file descriptor flags
144 .\"O (the close-on-exec flag).
145 .\"O The close-on-exec flag
146 .\"O .RB ( FD_CLOEXEC ;
147 .\"O see
148 .\"O .BR fcntl (2))
149 .\"O for the duplicate descriptor is off.
150 2¤Ä¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¦¥Õ¥é¥° (close-on-exec flag)
151 ¤ò¶¦Í­¤·¤Ê¤¤¡£Ê£À½¤µ¤ì¤¿¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î
152 close-on-exec flag
153 .RB ( fcntl (2)
154 »²¾È) ¤Ï off ¤È¤Ê¤ë¡£
155
156 .\"O .BR dup3 ()
157 .\"O is the same as
158 .\"O .BR dup2 (),
159 .\"O except that:
160 .BR dup3 ()
161 ¤Ï
162 .BR dup2 ()
163 ¤ÈƱ¤¸¤À¤¬¡¢°Ê²¼¤ÎÅÀ¤¬°Û¤Ê¤ë¡£
164 .IP * 3
165 .\"O The caller can force the close-on-exec flag to be set
166 .\"O for the new file descriptor by specifying
167 .\"O .BR O_CLOEXEC
168 .\"O in
169 .\"O .IR flags .
170 .\"O See the description of the same flag in
171 .\"O .BR open (2)
172 .\"O for reasons why this may be useful.
173 ¸Æ¤Ó½Ð¤·¸µ¤¬¡¢¿·¤·¤¤¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ·¤Æ
174 close-on-exec ¥Õ¥é¥°¤ò¶¯À©Åª¤ËÀßÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
175 ¤³¤ì¤ò¹Ô¤¦¤Ë¤Ï¡¢
176 .I flags
177 ¤Ë
178 .B O_CLOEXEC
179 ¤ò»ØÄꤹ¤ë¡£
180 ¤³¤Î¥Õ¥é¥°¤¬Ìò¤ËΩ¤ÄÍýͳ¤Ë¤Ä¤¤¤Æ¤Ï¡¢
181 .BR open (2)
182 ¤Î
183 .B O_CLOEXEC
184 ¥Õ¥é¥°¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
185 .IP *
186 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
187 .\"O If
188 .\"O .IR oldfd
189 .\"O equals
190 .\"O .IR newfd ,
191 .\"O then
192 .\"O .BR dup3 ()
193 .\"O fails with the error
194 .\"O .BR EINVAL .
195 .I oldfd
196 ¤¬
197 .I newfd
198 ¤ÈƱ¤¸¾ì¹ç¡¢
199 .BR dup3 ()
200 ¤Ï
201 .B EINVAL
202 ¥¨¥é¡¼¤Ç¼ºÇÔ¤¹¤ë¡£
203 .\"O .SH "RETURN VALUE"
204 .SH ÊÖ¤êÃÍ
205 .\"O On success, these system calls
206 .\"O return the new descriptor.
207 .\"O On error, \-1 is returned, and
208 .\"O .I errno
209 .\"O is set appropriately.
210 À®¸ù¤¹¤ë¤È¡¢¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¿·¤·¤¤¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
211 ¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤òÊÖ¤·¡¢
212 .I errno
213 ¤òŬÀÚ¤ËÀßÄꤹ¤ë¡£
214 .\"O .SH ERRORS
215 .SH ¥¨¥é¡¼
216 .TP
217 .\"O .B EBADF
218 .\"O .I oldfd
219 .\"O isn't an open file descriptor, or
220 .\"O .I newfd
221 .\"O is out of the allowed range for file descriptors.
222 .B EBADF
223 .I oldfd
224 ¤¬¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¤«¡¢
225 .I newfd
226 ¤¬¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤È¤·¤Æµö¤µ¤ì¤ëÈϰϤ«¤é³°¤ì¤Æ¤¤¤ë¡£
227 .TP
228 .B EBUSY
229 .\"O (Linux only) This may be returned by
230 .\"O .BR dup2 ()
231 .\"O or
232 .\"O .BR dup3 ()
233 .\"O during a race condition with
234 .\"O .BR open (2)
235 .\"O and
236 .\"O .BR dup ().
237 (Linux ¤Î¤ß)
238 .BR open (2)
239 ¤ä
240 .BR dup ()
241 ¤È¤Î¶¥¹ç¾õÂ֤ξì¹ç¤Ë¡¢
242 .BR dup2 ()
243 ¤ä
244 .BR dup3 ()
245 ¤Ï¤³¤Î¥¨¥é¡¼¤òÊÖ¤¹¤«¤â¤·¤ì¤Ê¤¤¡£
246 .TP
247 .B EINTR
248 .\"O The
249 .\"O .BR dup2 ()
250 .\"O or
251 .\"O .BR dup3 ()
252 .\"O call was interrupted by a signal; see
253 .\"O .BR signal (7).
254 .BR dup2 ()
255 ¤ä
256 .BR dup3 ()
257 ¤Î¸Æ¤Ó½Ð¤·¤¬¥·¥°¥Ê¥ë¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¡£
258 .BR signal (7)
259 »²¾È¡£
260 .TP
261 .B EINVAL
262 .\"O .RB ( dup3 ())
263 .\"O .I flags
264 .\"O contain an invalid value.
265 .RB ( dup3 ())
266 .I flags
267 ¤Ë̵¸ú¤ÊÃͤ¬Æþ¤Ã¤Æ¤¤¤ë¡£
268 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
269 .\"O Or,
270 .\"O .I oldfd
271 .\"O was equal to
272 .\"O .IR newfd .
273 ¤â¤·¤¯¤Ï¡¢
274 .I oldfd
275 ¤¬
276 .I newfd
277 ¤ÈƱ¤¸¤Ç¤¢¤Ã¤¿¡£
278 .TP
279 .\"O .B EMFILE
280 .\"O The process already has the maximum number of file
281 .\"O descriptors open and tried to open a new one.
282 .B EMFILE
283 ¥×¥í¥»¥¹¤¬¤¹¤Ç¤Ë¥ª¡¼¥×¥ó¤Ç¤­¤ëºÇÂç¿ô¤Þ¤Ç¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
284 ¤ò³«¤¤¤Æ¤¤¤Æ¡¢¤µ¤é¤Ë¿·¤·¤¤¤â¤Î¤ò³«¤³¤¦¤È¤·¤¿¡£
285 .\"O .SH VERSIONS
286 .SH ¥Ð¡¼¥¸¥ç¥ó
287 .\"O .BR dup3 ()
288 .\"O was added to Linux in version 2.6.27;
289 .\"O glibc support is available starting with
290 .\"O version 2.9.
291 .BR dup3 ()
292 ¤Ï¥Ð¡¼¥¸¥ç¥ó 2.6.27 ¤Ç Linux ¤ËÄɲ䵤줿¡£
293 glibc ¤Ë¤è¤ë¥µ¥Ý¡¼¥È¤Ï¥Ð¡¼¥¸¥ç¥ó 2.9 °Ê¹ß¤ÇÍøÍѤǤ­¤ë¡£
294 .\"O .SH "CONFORMING TO"
295 .SH ½àµò
296 .BR dup (),
297 .BR dup2 ():
298 SVr4, 4.3BSD, POSIX.1-2001.
299
300 .\"O .BR dup3 ()
301 .\"O is Linux-specific.
302 .BR dup3 ()
303 ¤Ï Linux ¸ÇÍ­¤Ç¤¢¤ë¡£
304 .\"O .\" SVr4 documents additional
305 .\"O .\" EINTR and ENOLINK error conditions.  POSIX.1 adds EINTR.
306 .\"O .\" The EBUSY return is Linux-specific.
307 .\" SVr4 ¤Ë¤Ï¾¤Ë EINTR, ENOLINK ¥¨¥é¡¼¾õÂ֤ε­½Ò¤¬¤¢¤ë¡£
308 .\" POSIX.1 ¤Ë¤Ï¾¤Ë EINTR ¤¬¤¢¤ë¡£
309 .\" EBUSY ¤¬ÊÖ¤µ¤ì¤ë¤Î¤Ï Linux Æȼ«¤Î¤â¤Î¤Ç¤¢¤ë¡£
310 .\"O .SH NOTES
311 .SH Ãí°Õ
312 .\"O The error returned by
313 .\"O .BR dup2 ()
314 .\"O is different from that returned by
315 .\"O .BR fcntl( "..., " F_DUPFD ", ..." )
316 .\"O when
317 .\"O .I newfd
318 .\"O is out of range.
319 .\"O On some systems
320 .\"O .BR dup2 ()
321 .\"O also sometimes returns
322 .\"O .B EINVAL
323 .\"O like
324 .\"O .BR F_DUPFD .
325 .I newfd
326 ¤¬ÈϰϤòĶ¤¨¤¿»þ¤ËÊÖ¤µ¤ì¤ë¥¨¥é¡¼¤Ï¡¢
327 .BR dup2 ()
328 ¤È
329 .BR fcntl( "..., " F_DUPFD ", ..." )
330 ¤Ç¤Ï°Û¤Ã¤Æ¤¤¤ë¡£
331 .BR dup2 ()
332 ¤¬
333 .B F_DUPFD
334 ¤ÈƱ¤¸¤è¤¦¤Ë
335 .B EINVAL
336 ¤òÊÖ¤¹¥·¥¹¥Æ¥à¤â¤¢¤ë¡£
337
338 .\"O If
339 .\"O .I newfd
340 .\"O was open, any errors that would have been reported at
341 .\"O .BR close 2()
342 .\"O time are lost.
343 .\"O A careful programmer will not use
344 .\"O .BR dup2 ()
345 .\"O or
346 .\"O .BR dup3 ()
347 .\"O without closing
348 .\"O .I newfd
349 .\"O first.
350 .I newfd
351 ¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¤È¡¢
352 .BR close (2)
353 ¤·¤¿»þ¤ËÊó¹ð¤µ¤ì¤ë¤Ï¤º¤Î¥¨¥é¡¼¤¬¼º¤ï¤ì¤Æ¤·¤Þ¤¦¡£
354 .BR dup2 ()
355 ¤ä
356 .BR dup3 ()
357 ¤ò»È¤¦Á°¤ËÀ褺
358 .I newfd
359 ¤ò¥¯¥í¡¼¥º¤¹¤ë¤è¤¦¤Ë¤·¤¿Êý¤¬¤¤¤¤¤À¤í¤¦¡£
360 .\"O .SH "SEE ALSO"
361 .SH ´ØÏ¢¹àÌÜ
362 .BR close (2),
363 .BR fcntl (2),
364 .BR open (2)