dup — duplicate an open file descriptor
int dup(int fildes);
is a file descriptor obtained from a
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).
Same file status flags (see
The new file descriptor is set to remain open across
The file descriptor returned is the lowest one available.
Upon successful completion, the file descriptor is returned
as a non-negative integer.
Otherwise, a value of -1 is returned and
is set to indicate the error.
fails if one or more of the following is true:
is not a valid open file descriptor.
Request violates the maximum number of open file descriptors.
was developed by AT&T and HP.
dup(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1