#include <unistd.h>
int dup(int oldfd);
int dup2(int oldfd, int newfd)
描述
创建已经存在的文件描述符的拷贝。
After a successful return from dup() or dup2(), the old and new file
descriptors may be used interchangeably. They refer to the same open
file description (see open(2)) and thus share file offset and file sta-
tus flags; for example, if the file offset is modified by using
lseek(2) on one of the descriptors, the offset is also changed for the
other.
The two descriptors do not share file descriptor flags (the close-on-
exec flag). The close-on-exec flag (FD_CLOEXEC; see fcntl(2)) for the
duplicate descriptor is off.
dup() uses the lowest-numbered unused descriptor for the new descrip-
tor.
dup2() makes newfd be the copy of oldfd, closing newfd first if neces-
sary.
#include <unistd.h>
int dup(int oldfd);
int dup2(int oldfd, int newfd);
复制一个文件描述符。语法: #include int dup(int oldfd); int dup2(int oldfd, int newfd)描述创建已经存在的文件描述符的拷贝。 After a successful return from dup() or dup2(), the old and new f