1dup(2) System Calls dup(2)
2
3
4
6 dup - duplicate an open file descriptor
7
9 #include <unistd.h>
10
11 int dup(int fildes);
12
13
15 The dup() function returns a new file descriptor having the following
16 in common with the original open file descriptor fildes:
17
18 o same open file (or pipe)
19
20 o same file pointer (that is, both file descriptors share one
21 file pointer)
22
23 o same access mode (read, write or read/write).
24
25
26 The new file descriptor is set to remain open across exec functions
27 (see fcntl(2)).
28
29
30 The file descriptor returned is the lowest one available.
31
32
33 The dup(fildes) function call is equivalent to:
34
35
36 fcntl(fildes, F_DUPFD, 0)
37
39 Upon successful completion, a non-negative integer representing the
40 file descriptor is returned. Otherwise, −1 is returned and errno is set
41 to indicate the error.
42
44 The dup() function will fail if:
45
46 EBADF The fildes argument is not a valid open file descriptor.
47
48
49 EINTR A signal was caught during the execution of the dup() func‐
50 tion.
51
52
53 EMFILE The process has too many open files (see getrlimit(2)).
54
55
56 ENOLINK The fildes argument is on a remote machine and the link to
57 that machine is no longer active.
58
59
61 See attributes(5) for descriptions of the following attributes:
62
63
64
65
66 ┌─────────────────────────────┬─────────────────────────────┐
67 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
68 ├─────────────────────────────┼─────────────────────────────┤
69 │Interface Stability │Standard │
70 ├─────────────────────────────┼─────────────────────────────┤
71 │MT-Level │Async-Signal-Safe │
72 └─────────────────────────────┴─────────────────────────────┘
73
75 close(2), creat(2), exec(2), fcntl(2), getrlimit(2), open(2), pipe(2),
76 dup2(3C), lockf(3C), attributes(5), standards(5)
77
78
79
80SunOS 5.11 28 Dec 1996 dup(2)