ffiles1
#include <stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
int main(int argc, char *argv[])
{
int fd1, fd2, fd3;
char c1, c2, c3;
char *fname = "abcde.txt";
fd1 = open(fname, O_RDONLY, 0);
fd2 = open(fname, O_RDONLY, 0);
fd3 = open(fname, O_RDONLY, 0);
dup2(fd2, fd3);
read(fd1, &c1, 1

本文详细分析了文件读写操作,包括ffiles1、ffiles2和ffiles3三个部分。ffiles1中展示了如何使用dup2进行文件描述符覆盖,影响后续的读取操作。ffiles2探讨了父子进程共享空间下文件读取的不同步行为。ffiles3则讲解了如何新建文件、追加内容以及利用dup实现文件描述符复制,最终导致文件内容的变化。
最低0.47元/天 解锁文章
817

被折叠的 条评论
为什么被折叠?



