【macOS】Too Many Open Files

Posted by 西维蜀黍 on 2021-08-28, Last Modified on 2022-02-19

System Level

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:

$ sysctl kern.maxfiles
$ sysctl kern.maxfilesperproc

You can increase the limits (at your own risk) with:

$ sysctl -w kern.maxfiles=20480
$ sysctl -w kern.maxfilesperproc=18000

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 /etc/launchd.conf like limit maxfiles and it will override whatever you put here.

Session/Shell Level

Once you’ve increased the system level’s FD limit (under /etc/sysctl.conf), 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 (.bashrc, .zshrc or whatever) if you want it to run every time you open a shell.