4 ms·
Yes, 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 duplicat
by ithkuil 3y ago
Yes, 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.