I need to get rid of the pesky "Too many open files in system" limit on OS X 10.7.1.
Is there a way?
According to this helpful article (which I recommend reading):
By default, the maximum number of files that Mac OS X can open is set to 12,288 and the maximum number of files a given process can open is 10,240.
You can check these with:
You can increase the limits (at your own risk) with:
sysctl -w kern.maxfiles=20480(or whatever number you choose)
sysctl -w kern.maxfilesperproc=18000(or whatever number you choose)
To make the change permanent, use
sudo to put your settings in
/etc/sysctl.conf (which you may have to create), like this:
Note: In OS X 10.10 or lower, you can add setting in
limit maxfiles and it will override whatever you put here.
Again, from the article:
Once you’ve done this, the kernel itself will have a maximum number of files but the shell might not. And since most processes that will take up this many files are going to be initiated by the shell you’re gonna want to increase that.
The command for that is:
ulimit -S -n 2048 # or whatever number you choose
That change is also temporary; it only lasts for the current shell session. You can add it to your shell configuration file (
.zshrc or whatever) if you want it to run every time you open a shell.
It seems like there is an entirely different method for changing the open files limit for each version of OS X!
For OS X Sierra (10.12.X) you need to:
Create a file at
/Library/LaunchDaemons/limit.maxfiles.plist and paste the following in (feel free to change the two numbers (which are the soft and hard limits, respectively):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>limit.maxfiles</string> <key>ProgramArguments</key> <array> <string>launchctl</string> <string>limit</string> <string>maxfiles</string> <string>64000</string> <string>524288</string> </array> <key>RunAtLoad</key> <true/> <key>ServiceIPC</key> <false/> </dict> </plist>
2. Change the owner of your new file:
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
3. Load these new settings:
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
4. Finally, check that the limits are correct:
launchctl limit maxfiles
You will need to increase your ulimit settings - it's pretty low on OS X these days - 256 by default. Add
ulimit -n 4096 or similar to your ~/.profile or equivalent and that will solve it in your local environment. Run
ulimit -a to check your current levels
To see the system settings, run this:
launchctl limit maxfiles
It is set quite a bit higher in Lion (10240) on a per process basis than it used to be. But if you are still hitting it there then you can set it higher using the same command with the desired levels. To make the changes permanent /etc/launchd.conf is where you need to add the relevant lines.
Other option may be finding the culprit:
sudo lsof -n | cut -f1 -d' ' | uniq -c | sort | tail
For the last one you could see what files are open:
sudo lsof -n | grep socketfil
And kill the process if so desired
From the comments:
For what it's worth, you can also get a list of the process IDs with the most open files using
lsof -n | sed -E 's/^[^ ]+[ ]+([^ ]+).*$/\1/' | uniq -c | sort | tail