文章目录 一、函数声明 二、解释 三、实例 一、函数声明 #include <unistd.h> int dup(int oldfd); int dup2(int oldfd, int newfd); 二、解释 dup将复制oldfd文件描述符,返回新的描述符 dup2将复制oldfd到指定的newfd上,如果newfd有已经存在的描述符则关闭(如果oldfd==newfd就不会关闭)