I am trying to do something that requires a large number of file descriptors

sudo ulimit -n 12288 is as high as Snow Leopard wants to go; beyond this results in

/usr/bin/ulimit: line 4: ulimit: open files: cannot modify limit: Invalid argument.

I want to raise the number much higher, say 100000. Is it possible?

link|improve this question

75% accept rate
feedback

2 Answers

up vote 4 down vote accepted

ulimit only changes the resource limits for the current shell and its children; sudo ulimit creates a root shell, adjusts its limits, and then exits (thus having, as far as I can see, no real effect). To exceed 12288, you need to adjust the kernel's kern.maxfiles and kern.maxfilesperproc parameters, and also (at least according to this blog entry, which is a summary of this discussion) a launchd limit. You can use launchctl limit to adjust all of these at once:

sudo launchctl limit maxfiles 1000000 unlimited

To make this permanent (i.e not reset when you reboot), create /etc/launchd.conf containing:

limit maxfiles 1000000 unlimited

Then you can use ulimit (but without the sudo) to adjust your process limit.

BTW, if this doesn't do it, you may be running into size limits in the kernel. If your model supports it, booting the kernel in 64-bit mode may help.

link|improve this answer
That works perfectly, thanks. – Chris Poole Jun 28 '11 at 11:57
feedback

It seems that OS X Lion will not permit "unlimited" as a value:

% sudo launchctl limit maxfiles 8192 unlimited
Neither the hard nor soft limit for "maxfiles" can be unlimited. Please use a numeric parameter for both.

Providing numerical values for both the soft and the hard limit does the job:

% sudo launchctl limit maxfiles 4096 8192
link|improve this answer
1  
If one of the values was unlimited, using -1 as value results in 12288. It's possible to use larger numeric values, e.g. sudo launchctl limit maxfiles 15000 150000. I'm not sure these settings have an effect then, though. – Daniel Beck Dec 10 '11 at 10:59
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.