一.复制一个现有的文件描述符dup() dup2() dup3()
函数原形:
#include <unistd.h>
int dup(
int oldfd);
int dup2(
int oldfd,
int newfd);
#define _GNU_SOURCE /* Seefeature_test_macros(7) */
#include <fcntl.h> /* Obtain O_* constant definitions */
#include <unistd.h>
int dup3(
int oldfd,
int newfd,
int flags);
参数: 返回值:成功返回一个新的文件描述符,失败返回 -1 dup()返回的描述符号一定是当前可用文件描述符的最小值 dup2()可以用newfd指定的新描述符的值,如果newfd已经打开则先关闭,如果oldfd==newfd则不关闭dup2()返回newfd
转载请注明原文地址: https://ju.6miu.com/read-10368.html