duplicate an open file descriptor
int dup(int fildes);
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
The file descriptor
returned is the lowest one available.
On success, dup returns a non-negative integer,
namely the file descriptor.
On failure, dup returns -1 and sets errno to identify the error.
In the following conditions, dup fails and sets errno to:
is not a valid open
A signal was caught during the dup system call.
The process has too many open files
fildes is on a remote machine and the link
to that machine is no longer active.
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.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004