3 ms·
"Random files opened by the parent" were, as a rule, deliberately given to the child. You would use CLOEXEC if you don't want that. Please don't let your child
by o11c 2y ago
"Random files opened by the parent" were, as a rule, deliberately given to the child. You would use CLOEXEC if you don't want that.
Please don't let your children trash something you gave them just because they don't appreciate it yet.
- int_19h 2y agoThat's the way it's supposed to be, in the theory. But because this API requires extra effort to use, and by default FDs are inherited, in practice most of the time it is not intentional. The correct design would be to explicitly whitelist the FDs that the child process will inherit. This is exactly what Python does - its standard API to spawn subprocesses not only has close_fds=True set by default, it also has pass_fds where you list the ones that should not be closed. FWIW I also don't see why the parent should care if the child closes its inherited descriptors, since it retains its own copy which remains open.
- themk 2y agoThe problem is that process A might spawn process B that might spawn process C. A may have opened an fd for C to use, and B has no way of knowing that. You really shouldn't be closing random fds that you inherited.