Linux 系统库函数 -- dup 和 dup2

来源:互联网 发布:西交大网络教育 编辑:程序博客网 时间:2024/05/04 07:16

    The dupsystem calls provide a way of duplicating a file descriptor, giving us two or more different descriptors that access the same file. These might be used for reading and writing to different locations in the file. The dupsystem call duplicates a file descriptor, fildes, returning a new descriptor. The dup2 system call effectively copies one file descriptor to another by specifying the descriptor to use for the copy.

    Here’s the syntax:


#include
int dup(int fildes);
int dup2(int fildes, int fildes2);


    These calls can also be useful when you’re using multiple processes communicating via pipes.