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 これらのシステムコールは、ファイル・ディスクリプタ
82 が有効なファイルディスクリプタでない場合、その呼び出しは失敗し、
97 これらのシステムコールのいずれかが成功を返した場合には、
98 古いファイル・ディスクリプタと新しいファイル・ディスクリプタは
100 2つのファイル・ディスクリプタは同じファイル記述 (description)
102 参照) を参照しており、したがってファイルオフセットやファイル状態フラグが
103 共有される。例えば、一方のディスクリプタに対して
105 を使ってファイルオフセットを変更した場合、もう一方のディスクリプタの
108 2つのディスクリプタはファイル・ディスクリプタ・フラグ (close-on-exec flag)
119 呼び出し元が、新しいファイル・ディスクリプタに対して
120 close-on-exec フラグを強制的に設定することができる。
132 .\" FIXME . To confirm with Al Viro that this was intended, and its rationale
142 成功すると、これらのシステムコールは新しいディスクリプタを返す。
150 がオープンされたファイル・ディスクリプタでないか、
152 がファイル・ディスクリプタとして許される範囲から外れている。
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.
198 .\" SVr4 には他に EINTR, ENOLINK エラー状態の記述がある。
199 .\" POSIX.1 には他に EINTR がある。
200 .\" EBUSY が返されるのは Linux 独自のものである。
206 .BR fcntl( "..., " F_DUPFD ", ..." )
218 した時に報告されるはずのエラーが失われてしまう。