Raise Open File Limits in OS X
in OS X 10.4 to macOS sierra 10.12 and maybe higher!
Create Launcher Script:
Copy this entire code block and paste it into your terminal and push Return to create this file for you with correct permissions. It will (probably) ask for your password:
cat <<EOM|sudo tee /Library/LaunchDaemons/limit.maxfiles.plist > /dev/null 2>&1 <?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>524288</string> <string>524288</string> </array> <key>RunAtLoad</key> <true /> </dict> </plist> EOM
To activate this launcher without rebooting, run:
$ sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
There are three different things you should check (thus adding to the overall confusion of this process)
launchctl limit maxfiles
$ launchctl limit maxfiles maxfiles 524288 524288
Both values should be
524288(these are the 'soft' and 'hard' limits)
sysctl kern.maxfiles kern.maxfilesperproc
$ sysctl kern.maxfiles kern.maxfilesperproc kern.maxfiles: 524288 kern.maxfilesperproc: 524288
Again, both should be
You must open a new terminal for this!
$ ulimit -n 524288
The value returned should be
524288! If it's not, proceed to "Troubleshooting" below. If it is
524288, then you're all done!
Permissions on the
/Library/LaunchDaemons/limit.maxfiles.plist file are very important. If you used these instructions, they should be correct by default, but make sure it is owned by user
root and group
wheel and umask 0644 (i.e.
-rw-r--r-- root:wheel when you do
ls -l on it)
$ sudo chmod 0644 /Library/LaunchDaemons/limit.maxfiles.plist $ sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
Cleanup Old Configurations
There has never been an officially recommended way of doing this and Apple has randomly changed the way it could be done throughout the years. If you're still finding that the
ulimit -n is not returning the proper value, you should check some other places where it may be misconfigured. This should fix the problem for you, but sometimes old files may be getting in the way.
Make sure to remove any other
sysctl commands involving
maxfilesperproc and any
ulimit -n <blah> commands that you may have in:
Additionally, check your shell profile settings: