4 ms·
How could the external command change the seek offset in its parent process? Did the seek system call change it in both? (I guess I've forgotten most of what I
by abecedarius 3y ago
How could the external command change the seek offset in its parent process? Did the seek system call change it in both?
(I guess I've forgotten most of what I ever knew about Unix system calls.)
- ithkuil 3y agoYes, that's what sharing a file descriptor means. You could have two file descriptors pointing to the same file (either by opening the same file or by duplicating the file descriptor with the dup syscall) and in that case the two file descriptors would have each their own file position
- abecedarius 3y agoThanks. I'm still surprised because in my fuzzy memory the shell after forking keeps only the stdin/stdout/stderr fds open by the time it execs the command -- but it makes sense that you could arrange to make this work with a different setup. BTW if we're making changes like that, you could also make I/O redirection the responsibility of a command instead of the shell, similar to this article's 'if' command. I wonder how much else you could take out of the shell.
- ithkuil 3y agoThe O_CLOEXEC flag of open (and FD_CLOEXEC flag of fctl) can help you control which file descriptors will be automatically closed on exec. Otherwise, you have to manually close the files between a fork and an exec.