LWN.net Logo

Fun with file descriptors

Fun with file descriptors

Posted Jun 7, 2007 4:42 UTC (Thu) by felixfix (subscriber, #242)
Parent article: Fun with file descriptors

Hmmm ... It's been a while since I wrote threaded socket code, so I may be barking up a non-existent tree. But if a new open() flag to create a non-sequential fd is not welcome because socket(), for instance, does not have these flags, why is a new O_CLOEXEC flag acceptable? Is it the case that no socket fd will ever be closed upon exec? Or is it because exec is (still?) a no-no in threaded programs?


(Log in to post comments)

Fun with file descriptors

Posted Jun 14, 2007 7:51 UTC (Thu) by slamb (guest, #1070) [Link]

I'm not sure about a "no-no", but exec*() is generally preceded by fork(), and I'm told a fork() in large threaded programs can be extremely slow. Apache uses an external forking server for this reason. Other caveats include that in the fork()ed child process, it is as if all other threads suddenly died, and they still hold whatever mutexes they were holding. So any resources the child requires (before calling exec*()) need a pthread_atfork(3) handler or similar.

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds