dup(S)
dup --
duplicate an open file descriptor
Synopsis
#include <unistd.h>
int dup(int fildes);
Description
dup duplicates an open file descriptor.
fildes is a file descriptor obtained from
a creat, open, dup, fcntl, pipe,
or ioctl system call.
dup returns a new file descriptor
having the following in common with the original:
-
Same open file (or pipe).
-
Same file pointer
(i.e., both file descriptors share one file pointer).
-
Same access mode (read, write or read/write).
The new file descriptor is set to remain open across
exec system calls
[see
fcntl(S)].
The file descriptor
returned is the lowest one available.
Return values
On success, dup returns a non-negative integer,
namely the file descriptor.
On failure, dup returns -1 and sets errno to identify the error.
Errors
In the following conditions, dup fails and sets errno to:
EBADF-
fildes
is not a valid open
file descriptor.
EINTR-
A signal was caught during the dup system call.
EMFILE-
The process has too many open files
[see
getrlimit(S)].
ENOLINK-
fildes is on a remote machine and the link
to that machine is no longer active.
References
close(S),
creat(S),
dup2(S),
exec(S),
fcntl(S),
getrlimit(S),
lockf(S),
open(S),
pipe(S)
Notices
Considerations for threads programming
Open file descriptors are a process resource
and available to any sibling thread;
if used concurrently, actions by one thread can interfere with
those of a sibling.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005