dup2(3N) dup2(3N)NAME dup2 - duplicates a descriptor SYNOPSIS dup2(oldd, newd) int oldd, newd; DESCRIPTION dup2 causes newd to become a duplicate of oldd. If newd is already in use, the descriptor is first deallocated as if a close(2) call had been done first. The object referenced by the descriptor does not distinguish between references using oldd and newd in any way. Thus, if newd and oldd are duplicate references to an open file, read(2), write(2), and lseek(2) calls all move a single pointer into the file. If a separate pointer into the file is desired, a different object reference to the file must be obtained by issuing an additional open(2) call. STATUS MESSAGES AND VALUES The value -1 is returned if an error occurs in either call. The external variable errno indicates the cause of the error. The dup2 program fails if: EBADF oldd or newd is not a valid active descriptor EMFILE Too many descriptors are active. SEE ALSO accept(2N), close(2), dup(2), fcntl(2), getdtablesize(2N), open(2), pipe(2), socket(2N) January 1992 1