1 .\" Hey Emacs! This file is -*- nroff -*- source.
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>
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 1993-07-21, Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1994-08-21, Michael Chastain <mec@shell.portal.com>:
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()
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
46 .TH DUP 2 2010-09-10 "Linux" "Linux Programmer's Manual"
48 dup, dup2, dup3 \- ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊ£À½¤¹¤ë
51 .B #include <unistd.h>
53 .BI "int dup(int " oldfd );
54 .BI "int dup2(int " oldfd ", int " newfd );
56 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) »²¾È */"
57 .B #include <unistd.h>
59 .BI "int dup3(int " oldfd ", int " newfd ", int " flags );
62 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
67 ¤ÏºÇ¤â¾®¤µ¤¤ÈÖ¹æ¤Î̤»ÈÍѤΥǥ£¥¹¥¯¥ê¥×¥¿¤ò
68 ¿·¤·¤¤¥Ç¥£¥¹¥¯¥ê¥×¥¿¤È¤·¤Æ»ÈÍѤ¹¤ë¡£
75 ¤ÎÊ£À½¤È¤·¤ÆºîÀ®¤¹¤ë¡£
79 °Ê²¼¤ÎÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È¡£
82 ¤¬Í¸ú¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¾ì¹ç¡¢¤½¤Î¸Æ¤Ó½Ð¤·¤Ï¼ºÇÔ¤·¡¢
87 ¤¬Í¸ú¤Ê¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¡¢
97 ¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Î¤¤¤º¤ì¤«¤¬À®¸ù¤òÊÖ¤·¤¿¾ì¹ç¤Ë¤Ï¡¢
98 ¸Å¤¤¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤È¿·¤·¤¤¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï
99 ¸ß¤¤¤Ë²Ä´¹¤Ê¤â¤Î¤È¤·¤Æ»È¤¦¤³¤È¤¬¤Ç¤¤ë¡£
100 2¤Ä¤Î¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ÏƱ¤¸¥Õ¥¡¥¤¥ëµ½Ò (description)
102 »²¾È) ¤ò»²¾È¤·¤Æ¤ª¤ê¡¢¤·¤¿¤¬¤Ã¤Æ¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤ä¥Õ¥¡¥¤¥ë¾õÂ֥ե饰¤¬
103 ¶¦Í¤µ¤ì¤ë¡£Î㤨¤Ð¡¢°ìÊý¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ·¤Æ
105 ¤ò»È¤Ã¤Æ¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤òÊѹ¹¤·¤¿¾ì¹ç¡¢¤â¤¦°ìÊý¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î
106 ¥ª¥Õ¥»¥Ã¥È¤âÊѲ½¤¹¤ë¡£
108 2¤Ä¤Î¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¦¥Õ¥é¥° (close-on-exec flag)
109 ¤ò¶¦Í¤·¤Ê¤¤¡£Ê£À½¤µ¤ì¤¿¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î
112 »²¾È) ¤Ï off ¤È¤Ê¤ë¡£
117 ¤ÈƱ¤¸¤À¤¬¡¢°Ê²¼¤ÎÅÀ¤¬°Û¤Ê¤ë¡£
119 ¸Æ¤Ó½Ð¤·¸µ¤¬¡¢¿·¤·¤¤¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ËÂФ·¤Æ
120 close-on-exec ¥Õ¥é¥°¤ò¶¯À©Åª¤ËÀßÄꤹ¤ë¤³¤È¤¬¤Ç¤¤ë¡£
126 ¤³¤Î¥Õ¥é¥°¤¬Ìò¤ËΩ¤ÄÍýͳ¤Ë¤Ä¤¤¤Æ¤Ï¡¢
130 ¥Õ¥é¥°¤ÎÀâÌÀ¤ò»²¾È¤Î¤³¤È¡£
132 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
142 À®¸ù¤¹¤ë¤È¡¢¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¿·¤·¤¤¥Ç¥£¥¹¥¯¥ê¥×¥¿¤òÊÖ¤¹¡£
143 ¥¨¥é¡¼¤Î¾ì¹ç¡¢\-1 ¤òÊÖ¤·¡¢
150 ¤¬¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¤«¡¢
152 ¤¬¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤È¤·¤Æµö¤µ¤ì¤ëÈϰϤ«¤é³°¤ì¤Æ¤¤¤ë¡£
159 ¤È¤Î¶¥¹ç¾õÂ֤ξì¹ç¤Ë¡¢
163 ¤Ï¤³¤Î¥¨¥é¡¼¤òÊÖ¤¹¤«¤â¤·¤ì¤Ê¤¤¡£
169 ¤Î¸Æ¤Ó½Ð¤·¤¬¥·¥°¥Ê¥ë¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¡£
176 ¤Ë̵¸ú¤ÊÃͤ¬Æþ¤Ã¤Æ¤¤¤ë¡£
177 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
185 ¥×¥í¥»¥¹¤¬¤¹¤Ç¤Ë¥ª¡¼¥×¥ó¤Ç¤¤ëºÇÂç¿ô¤Þ¤Ç¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
186 ¤ò³«¤¤¤Æ¤¤¤Æ¡¢¤µ¤é¤Ë¿·¤·¤¤¤â¤Î¤ò³«¤³¤¦¤È¤·¤¿¡£
189 ¤Ï¥Ð¡¼¥¸¥ç¥ó 2.6.27 ¤Ç Linux ¤ËÄɲ䵤줿¡£
190 glibc ¤Ë¤è¤ë¥µ¥Ý¡¼¥È¤Ï¥Ð¡¼¥¸¥ç¥ó 2.9 °Ê¹ß¤ÇÍøÍѤǤ¤ë¡£
194 SVr4, 4.3BSD, POSIX.1-2001.
197 ¤Ï Linux ¸ÇͤǤ¢¤ë¡£
198 .\" SVr4 ¤Ë¤Ï¾¤Ë EINTR, ENOLINK ¥¨¥é¡¼¾õÂ֤ε½Ò¤¬¤¢¤ë¡£
199 .\" POSIX.1 ¤Ë¤Ï¾¤Ë EINTR ¤¬¤¢¤ë¡£
200 .\" EBUSY ¤¬ÊÖ¤µ¤ì¤ë¤Î¤Ï Linux Æȼ«¤Î¤â¤Î¤Ç¤¢¤ë¡£
203 ¤¬ÈϰϤòĶ¤¨¤¿»þ¤ËÊÖ¤µ¤ì¤ë¥¨¥é¡¼¤Ï¡¢
206 .BR fcntl( "..., " F_DUPFD ", ..." )
213 ¤òÊÖ¤¹¥·¥¹¥Æ¥à¤â¤¢¤ë¡£
216 ¤¬¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¤È¡¢
218 ¤·¤¿»þ¤ËÊó¹ð¤µ¤ì¤ë¤Ï¤º¤Î¥¨¥é¡¼¤¬¼º¤ï¤ì¤Æ¤·¤Þ¤¦¡£
224 ¤ò¥¯¥í¡¼¥º¤¹¤ë¤è¤¦¤Ë¤·¤¿Êý¤¬¤¤¤¤¤À¤í¤¦¡£