NoneDup2() is a c system call that duplicates a file descriptor. Also use this tag for questions about the related system call dup().

Usage: int dup2(int oldfd, int newfd);

The dup2() is a system call in C that creates a copy of a given file descriptor specified in newfd. dup2() is often used with pipes.

The difference between dup() and dup2() is that dup() always uses the lowest-numbered unused file descriptor whereas you specify the new destination file descriptor number in the second argument newfd.

dup2(), along with dup(), conforms to POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.

See the Linux manual page for dup2(), or the POSIX specification for dup2(), for more details.