Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C语言中的文件描述符_C_File_Posix - Fatal编程技术网

C语言中的文件描述符

C语言中的文件描述符,c,file,posix,C,File,Posix,让我们假设在我的操作系统中存在N个文件描述符。执行以下代码后,操作系统将有多少个文件描述符: int fd = dup(oldfd); 那么: int fd = dup2(oldfd,newfd); 谢谢 它在手册页中给出。调用任意一个文件描述符后,您将拥有N+1文件描述符 From manpages ... dup and dup2 create a copy of the file descriptor oldfd. After successfu

让我们假设在我的操作系统中存在N个文件描述符。执行以下代码后,操作系统将有多少个文件描述符:

    int fd = dup(oldfd);
那么:

   int fd = dup2(oldfd,newfd);

谢谢

它在手册页中给出。调用任意一个文件描述符后,您将拥有
N+1
文件描述符

From manpages
    ...
    dup and dup2 create a copy of the file descriptor oldfd.

    After successful return of dup or dup2, the old and new descriptors 
    may be used interchangeably. 

    dup uses the lowest-numbered unused descriptor for the new descriptor.
    ...

因此,使用未使用的描述符作为新描述符。这应该可以回答您的问题。

手册中给出了答案。调用任意一个文件描述符后,您将拥有
N+1
文件描述符

From manpages
    ...
    dup and dup2 create a copy of the file descriptor oldfd.

    After successful return of dup or dup2, the old and new descriptors 
    may be used interchangeably. 

    dup uses the lowest-numbered unused descriptor for the new descriptor.
    ...

因此,使用未使用的描述符作为新描述符。这应该能回答你的问题。

你为什么不自己试试呢?这是家庭作业吗?听起来像是我的系统编程课。这不是家庭作业,我的电脑上也没有安装c编译器。你为什么不自己试试呢?这是家庭作业吗?听起来像是我的系统编程课。这不是家庭作业,我也没有在pc上安装c编译器。