#include <unistd.h>int dup2(int oldfd, int newfd);
The dup2()system call performs the same task as dup, but instead of using the lowest-numbered unused file descriptor, it uses the file descriptor number specified in newfd. In other words, the file descriptornewfd is adjusted so that it now refers to the same open file description as oldfd.