Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Which command / configuration file controls the open file limits on OS X? Is there a different command for OS X 10.5 / 10.6 / 10.7? The options I explore below are ulimit, sysctl, and launchctl

"Too many open files" is apparently a common error on Leopard, perhaps other versions of OS X:

How to properly increase ulimit -n on Lion?

There are many (related?) ways to view the open file limits:

$ ulimit -a
core file size          (blocks, -c) 0
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) 2048
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 512
virtual memory          (kbytes, -v) unlimited

$ launchctl limit
cpu         unlimited      unlimited      
filesize    unlimited      unlimited      
data        unlimited      unlimited      
stack       8388608        67104768       
core        0              unlimited      
rss         unlimited      unlimited      
memlock     unlimited      unlimited      
maxproc     1024           2048           
maxfiles    2048           4096       

$ sysctl -a | grep files
kern.maxfiles = 32768
kern.maxfilesperproc = 16384
kern.maxfiles: 32768
kern.maxfilesperproc: 16384
kern.num_files: 2049

It has been claimed in some of the above posts that these can be modified with the following commands:

sudo launchctl limit maxfiles 16384 32768
sudo ulimit -n 32768
sudo sysctl -w kern.maxfilesperproc=16384
sudo sysctl -w kern.maxfiles=32768

However, out of the above commands, only the sysctl commands have any apparently effect (i.e. ulimit -n and launchctl limit show no change after the above commands have been entered, while sysctl -a does show the requested changes).

The corresponding locations to change these parameters for the OS are:


(discovered one answer: ulimit only controls the current shell

share|improve this question
Is there a question here? – user479 Dec 14 '11 at 18:25
Yeah... at the bottom. I had hoped that showing my research would be helpful to some, as it summarizes some very long threads elsewhere. I'm also not convinced any of the "solutions" I've posted actually work; they've behaved inconsistently (and unfortunately un-reproducibly) on my machine – keflavich Dec 14 '11 at 18:44
May I suggest moving your question to the top, to make it more clear? You're welcome to leave in your research. – user479 Dec 14 '11 at 18:48
re: bneely - infrequently, but when it happens, nearly everything on the machine stops functioning. I've noted problems in particular with Quicksilver and Google Chrome, and the problems are correlated with failures of mDNSResponder. However, I tried to keep this general, as others who have experienced this problem in the linked posts had different causes. – keflavich Dec 14 '11 at 21:54
Had this problem running emacs on Lion. I've been using it only a couple days, so that counts as "frequent" to me. Emacs apparently uses pbcopy on emacs in order to manage the OSX clipboard. If using emacs makes the OS stop functioning because of a file limit, then I'd say it's a pretty important problem. (side note - it's surprising to me that the default would be just 256 files) – Cheeso Aug 15 '12 at 0:26
up vote 4 down vote accepted

The simple answer is there are multiple limits and the lowest limit that you reach in a specific instance will generate your error.

The ulimit level is set low to prevent one poor shell script from flooding the kernel with open files.

The kern.maxfilesperproc is there to leave a little room in the max files count so that one process can use most but not all of the open file handler space from the kernel.

For normal situations, the kern.maxfiles is the final limiting factor.

If you have a specific instance, feel free to post a second narrow question with the specifics you face, but in general it's more important to internalize the various limits and realize that when you spawn a process it inherits the defaults set so you can tweak things when needed and you hit certain limits.

share|improve this answer

The following should resolve most common problems (and are listed in order of their hierarchy):

echo 'kern.maxfiles=20480' | sudo tee -a /etc/sysctl.conf
echo -e 'limit maxfiles 8192 20480\nlimit maxproc 1000 2000' | sudo tee -a /etc/launchd.conf
echo 'ulimit -n 4096' | sudo tee -a /etc/profile


  1. You will need to restart for these changes to take effect.
  2. AFAIK you can no longer set limits to 'unlimited' under OS X
  3. launchctl maxfiles are bounded by sysctl maxfiles, and therefore cannot exceed them
  4. sysctl seems to inherit kern.maxfilesperproc from launchctl maxfiles
  5. ulimit seems to inherit it's 'open files' value from launchctl by default
  6. you can set a custom ulimit within /etc/profile, or ~/.profile ; while this isn't required I've provided an example
  7. Be cautious when setting any of these values to a very high number when compared with their default - the features exist stability/security. I've taken these example numbers that I believe to be reasonable, written on other websites.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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