svcadm(8)을 검색하려면 섹션에서 8 을 선택하고, 맨 페이지 이름에 svcadm을 입력하고 검색을 누른다.
dup3(3c)
dup2(3C) Standard C Library Functions dup2(3C)
NAME
dup2, dup3 - duplicate an open file descriptor
SYNOPSIS
#include <unistd.h>
int dup2(int fildes, int fildes2);
int dup3(int fildes, int fildes2, int flags);
DESCRIPTION
The dup2() function causes the file descriptor fildes2 to refer to the
same file as fildes. The fildes argument is a file descriptor referring
to an open file, and fildes2 is a non-negative integer less than the
current value for the maximum number of open file descriptors allowed
the calling process. See getrlimit(2). If fildes2 already refers to an
open file, not fildes, it is closed first. If fildes2 refers to fildes,
or if fildes is not a valid open file descriptor, fildes2 will not be
closed first.
The dup2() function is equivalent to fcntl(fildes, F_DUP2FD, fildes2).
The dup3() function causes the file descriptor fildes2 to refer to the
same file as fildes. The fildes argument is a file descriptor referring
to an open file, and fildes2 is a non-negative integer less than the
current value for the maximum number of open file descriptors allowed
the calling process. See getrlimit(2). If fildes2 already refers to an
open file, not fildes, it is closed first. If fildes2 refers to fildes,
an error is returned. The flags argument can include O_CLOEXEC and/or
O_CLOFORK; these flags respectively set FD_CLOEXEC and FD_CLOFORK on
the new file descriptor. If these flags are not set in the flags argu‐
ment, the corresponding flags will be cleared on the new file descrip‐
tor.
The dup3() function is equivalent to fcntl(fildes, F_DUP3FD, fildes2,
fd_flags), where fd_flags is a mapping of O_CLOEXEC/O_CLOFORK to
FD_CLOEXEC/FD_CLOFORK.
RETURN VALUES
Upon successful completion a non-negative integer representing the file
descriptor is returned. Otherwise, −1 is returned and errno is set to
indicate the error.
ERRORS
The dup2() and dup3() functions will fail if:
EBADF The fildes argument is not a valid open file descriptor.
EBADF The fildes2 argument is negative or is not less than the cur‐
rent resource limit returned by getrlimit(RLIMIT_NOFILE,
...).
EINTR A signal was caught during the function call.
EINVAL The fildes argument is the same file descriptor as the
fildes2 argument, or flags has bits set other than FD_CLOEXEC
or FD_CLOFORK.
ATTRIBUTES
See attributes(7) for descriptions of the following attributes:
tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE TYPEAT‐
TRIBUTE VALUE _ Interface StabilityCommitted _ MT-LevelAsync-Signal-
Safe _ StandardSee standards(7).
SEE ALSO
close(2), creat(2), exec(2), fcntl(2), getrlimit(2), open(2), pipe(2),
attributes(7), standards(7)
HISTORY
The dup3() function was added to Oracle Solaris in Solaris 11.4.0.
The dup2() function has been included in all Sun and Oracle releases of
Solaris.
Oracle Solaris 11.4 27 Aug 2025 dup2(3C)