Forces a file descriptor to reference the same open file as another file descriptor.
#include <unistd.h> int dup2 ( int fildes1, int fildes2);
(IN) Specifies the file descriptor to be duplicated.
(IN) Specifies the file descriptor to change so that it references the same file as the fildes1 parameter.
If successful, returns a nonnegative integer that is the file descriptor. Otherwise, returns a -1 and sets errno to one of the following values:
The fildes1 parameter must be a file descriptor to a file that is already open. If fildes2 references a file that is already open, that file is closed before fildes2 is forced to reference the file for fildes1.