On Saturday, 9 March 2013 at 18:44:45 UTC, Lars T. Kyllingstad wrote:
On Saturday, 9 March 2013 at 18:35:25 UTC, Steven Schveighoffer wrote:
How do you loop over all open ones?  Just curious :)

You don't. That is why I said solution (3) sucks too. :) You have to loop over all possible non-std file descriptors, i.e. from 3 to the maximum number of open files. (On my Ubuntu installation, this is by default 1024, but may be as much as 4096. I don't know about other *NIXes)

Here is how to do it:

import core.sys.posix.unistd, core.sys.posix.sys.resource;
rlimit r;
getrlimit(RLIMIT_NOFILE, &r);
for (int i = 0; i < r.rlim_cur; ++i)
    close(i);

BTW, core.sys.posix.sys.resource currently doesn't exist, we have to create it.

Lars

Reply via email to