👩💻 Join our community of thousands of amazing developers!
references: https://copyconstruct.medium.com/nonblocking-i-o-99948ad7c957 Fork/Dup FileEntries fork系统调用将会导致父进程中的所有文件描述符都被共享到子进程中 父进程和子进程将会使用同一个文件描述符,而且在FileEntry中的偏移量也是一致的 这里有一个示例项目,代码如下: #include #include #include #include int main(char* argv[]) { int fd = open("abc.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666); pid_t pid = fork(); if (0 == pid) { sleep(1); printf("child fd offset before write %ld\n", lseek(fd, 0, SEEK_CUR)); write(fd, "xyz", 3); pr...