版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32768743/article/details/87433675
猜测是4
第一个fd1是3,第一个fd2是4,关闭后4应该释放,再打开,又是4
实验
代码
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int fd1, fd2;
fd1 = open("foo.txt", O_RDONLY, 0);
printf("fd1 = %d\n", fd1);
fd2 = open("bar.txt", O_RDONLY, 0);
printf("fd2 = %d\n", fd2);
close(fd2);
fd2 = open("bar.txt", O_RDONLY, 0);
printf("fd2 = %d\n", fd2);
exit(0);
}