DUP(2) DUP(2) NAME dup, dup2 - duplicate an open file descriptor SYNOPSIS int dup(fildes) int fildes; int dup2(fildes, fildes2) int fildes, fildes2; DESCRIPTION Given a file descriptor dup allocates another file descrip- tor synonymous with the original. The new file descriptor is returned. In dup2, fildes is a file descriptor referring to an open file, and fildes2 is an integer in the range of legal file descriptors. Dup2 causes fildes2 to refer to the same file and returns fildes2. If fildes2 already referred to another open file, it is closed first. SEE ALSO open(2), pipe(2), fd(4) DIAGNOSTICS EBADF, EMFILE BUGS Dup of a file descriptor greater than 63 turns into a dup2 with a random second argument.