csapp ch10.5 练习题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32768743/article/details/87432763

在这里插入图片描述
在这里插入图片描述
猜测是o,因为dup2后,是同一个文件表项
书上
在这里插入图片描述
实验
在这里插入图片描述
代码

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
    int fd1, fd2;
    char c;
    fd1 = open("foobar.txt", O_RDONLY, 0);
    fd2 = open("foobar.txt", O_RDONLY, 0);
    read(fd2, &c, 1);
    dup2(fd2, fd1);
    read(fd1, &c, 1);
    printf("c = %c\n", c);
    exit(0);
}

答案
在这里插入图片描述

猜你喜欢

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