int dup(int fildes);
int dup2(int fildes, int fildes2);
dup() duplicates an existing object descriptor and returns its value to the calling process. The argument
fildes is a small non-negative integer index in the per-process descriptor table. The new descriptor returned by the call is the lowest numbered descriptor currently not in use by the process.
dup2(), the value of the new descriptor
fildes2 is specified. If
fildes2 are equal, then
fildes2; no other changes are made to the existing descriptor. Otherwise, if descriptor
fildes2 is already in use, it is first deallocated as if a
close(2) call had been done first.