Did you ever run into the problem of too many open files on Mac OS X? This is not very surprising, because when you open a new shell, you can see that the limit of open files for this process is set to a not very high value:
andromeda:~ martin$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) 6144
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 256
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 266
virtual memory (kbytes, -v) unlimited
However, if you want to increase this limit, you might run into an error like this:
andromeda:~ martin$ ulimit -n 15000
-bash: ulimit: open files: cannot modify limit: Operation not permitted
You may rightly consider this some how odd, because when you look at the hard limit, you will find it set to unlimited:
andromeda:~ martin$ ulimit -H -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) unlimited
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 65532
cpu time (seconds, -t) unlimited
max user processes (-u) 532
virtual memory (kbytes, -v) unlimited
Now, under Mac OS X, the true hard limit can be shown with
andromeda:~ martin$ sysctl kern.maxfiles kern.maxfilesperproc
kern.maxfiles: 12288
kern.maxfilesperproc: 10240
In order to double these values run
sudo sysctl -w kern.maxfilesperproc=20480 kern.maxfiles=24576
Password:
kern.maxfilesperproc: 10240 -> 20480
kern.maxfiles: 12288 -> 24576
Now you can change the value for the current process without an error:
andromeda:~ martin$ ulimit -n 15000
andromeda:~ martin$