csapp ch10.6 家庭作业

版权声明:本文为博主原创文章,未经博主允许不得转载。 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);
}

猜你喜欢

转载自blog.csdn.net/qq_32768743/article/details/87433675