When working on my mac with many applications opened I sometimes came across this kind of errors:
Too many open files in system
If I was lucky only one specific application refused to work properly. But occasionally the whole system would become unresponsive and even decline to kill processes.
This command revealed the problem:
$ launchctl limit maxfiles maxfiles 256 Unlimited
It turned out that apple had set the limit of open file descriptors to an unreasonably low value.
After trying out many solutions of which some did not work at all or at most temporarilly I found this solution which seems to be permanent and at least works under Catalina:
$ cat /Library/LaunchDaemons/limit.maxfiles.plist
<?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>65536</string> <string>65536</string> </array> <key>RunAtLoad</key> <true /> </dict> </plist>
$ launchctl load /Library/LaunchDaemons/limit.maxfiles.plist
After this step a reboot is required.
– reboot –
$ launchctl limit maxfiles maxfiles 65536 65536
After every change the service has to be unloaded and loaded again:
$ launchctl unload /Library/LaunchDaemons/limit.maxfiles.plist $ launchctl load /Library/LaunchDaemons/limit.maxfiles.plist