On Wed, Sep 1, 2010 at 1:33 AM, Dave Keck <davek...@gmail.com> wrote: > Off topic 2: It's strange behavior in the first place, since AFAIK, > there's no efficient way of closing open descriptors short of for(i = > 3; i < getdtablesize(); i++) close(i);
It's actually normal and necessary behavior for a general-purpose subprocess creator. If it didn't close all other files, then every file currently open in your application (including those opened by libraries you don't control, threads doing completely unrelated things, etc.) would get inherited by the child process and stay open for as long as the child is open. If the child then spawns subprocesses of its own, they build up even further, and can eventually lead to resource exhaustion. The loop you describe is ugly but it works. (At least it does on OS X. In general, I don't think there's any guarantee that getdbtablesize() will return any sort of reasonably small number.) It appears that on other OSes the standard way to handle this is to read through the /proc/getpid()/fd/ directory to find out exactly which file descriptors are open. On OS X, you could read the contents of /dev/fd/ to accomplish the same thing. It appears that NSTask uses the uglier getdbtablesize() loop though. Mike _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com