In macOS Sierra, as on all modern operating system, there are limits on how many files can be open at a time. There are also limitations on how many processes, or programs, can run simultaneously. Apple has set these limits very conservatively, but those limits can cause problems in the form of a “too many open files” error. Let’s take a look at how to fix that, if you dare.
Follow These Steps With Caution, and Only on macOS Sierra 10.12
When I first modified my system’s maximum file open and running process limit, it froze several processes (including Terminal itself, and the Finder). I couldn’t force-quit any apps, couldn’t get any response from right-clicks, and was forced to manually power my Mac Mini off and boot into Recovery Mode to undo the damage I had done. I briefly thought I’d have to restore from Time Machine, but thankfully was able to reverse the changes I had made without resorting to that method. So, let me repeat: follow these steps with caution, and only on macOS Sierra 10.12.
Why Limit My Computer?
Deep in the core of macOS, we’ll find these limitations. To be more precise, the limits are actually deep in the kernel, the master process that runs everything else. This limit exists on all computer systems, to prevent programs from running amok and draining all of your system memory (RAM).
Apple, catering primarily to casual consumer users, has set these limits very conservatively. By default, a user can only have 256 files open and can only have 709 processes running simultaneously. By way of comparison, an Ubuntu installation on my Mac Mini allows for more than 33,000 open files concurrently, and I could not find a limit on the number of simultaneous running processes.
Pushing the Limits
These limitations are fine for casual Mac users, but developers often run afoul of them. The result, quite often, is an error message: “Too many files open in system.”
You can see these limits for yourself. Note that you may need to have UNIX tools and/or Xcode installed for these tests to work. Assuming you have the following commands, you should be able to see the limitations for yourself.
From Applications/Utilities/Terminal, issue these commands:
That will show you the system limits on open files and running processes. You’ll find the user limits by issuing this command in Terminal:
If you’ve run into the “Too many files open” error, let’s look at how to resolve it by increasing the maximum limits.
First, Disable System Integrity Protection (SIP)
Before you can change the limitations, you’ll need to disable SIP. SIP was introduced in in OS X El Capitan to prevent certain system-owned files and directories from being modified by processes that don’t have the right entitlements. Even the root user, or a user with root privileges (sudo), can’t modify these files without SIP being disabled. To disable this mechanism, you’ll need to reboot into Recovery Mode by restarting your Mac and holding down Command-R when you hear the startup chime, and until the Apple logo appears.
Once your Mac has booted into Recovery Mode, you should click Utilities from the top menu bar, then Terminal. In Terminal, issue the following command:
Once that’s done, you can reboot your Mac normally and log in.
Configuring Your New File Limits
Once you’ve logged in, you should once again open Terminal. In Terminal, type the following command:
sudo nano /Library/LaunchDaemons/limit.maxfiles.plist
Copy and paste the following content into the text editor that’s opened in your Terminal window. Provide your user password, if prompted.
<?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>
Note that to do this, you likely won’t be able to use the keyboard shortcut. Instead, right-click inside the Terminal window and choose paste. Then, press Control-X to save and close the text editor.
You’ll notice two numbers there: 64000 and 524288. The first is a soft limit, at which point your Mac will start preparing to stop allowing new file opens but still let them go. When the second number is reached, that’s the hard limit – at that point, you’ll get the “Too many files open in system” error.
Up Next: Increasing the Processes Limit