3 ms·
Yeah, and then some other thread opens a file descriptor while your loop is busy closing the last few file descriptors... CLOEXEC approaches are the only race
by alexlarsson 14y ago
Yeah, and then some other thread opens a file descriptor while your loop is busy closing the last few file descriptors...
CLOEXEC approaches are the only race free solutions.
- premchai21 14y agofork() only leaves the one thread running in the child, and at that point the fd tables are no longer shared, so trying to detect and close unwanted descriptors in the child after fork is not racy by itself as a way of mitigating the possibility of uncontrollable non-CLOEXEC opens elsewhere in the process (though this doesn't preclude it being a bad idea for other reasons).
- alexlarsson 14y agotrue, sorry.