int dup(int fd);
int dup2(int fd, int fd2);
The object referenced by the descriptor does not distinguish, in any way, between references using fd and the new descriptor returned. Thus, if the returned descriptor and are duplicate references to an open file, read.2 write.2 and lseek.2 calls all move a single pointer into the file, and append mode, non-blocking I/O and asynchronous I/O options are shared between the references. 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. The close-on-exec flag on the new file descriptor is unset.
With dup2, fd2 specifies the desired value of the new descriptor. If the descriptor fd2 is already in use, it is first deallocated as if a close.2 call had been performed on it.
Additionally, dup2 fails if:
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97