Allocate a new descriptor that refers to a file specified by a file descriptor returned by open, creat, or pipe.
#include <unistd.h> int dup (int file_desc1); int dup2 (int file_desc1, int file_desc2);
The argument file_desc1 is invalid if it does not describe an open file; file_desc2 is invalid if the new file descriptor cannot be allocated. If file_desc2 is connected to an open file, that file is closed.
n | The new file descriptor. |
-1 | Indicates that an invalid argument was passed to the function. |