Skip to content

Instantly share code, notes, and snippets.

@ko31
Last active April 17, 2020 02:47
Show Gist options
  • Save ko31/b9fe86eab9bfe61660e8fe69d9401914 to your computer and use it in GitHub Desktop.
Save ko31/b9fe86eab9bfe61660e8fe69d9401914 to your computer and use it in GitHub Desktop.
How to change file descriptor limit settings on Mac OS

I got a "too many open files" error.

Error: EMFILE: too many open files, open '/path/to/filename'

I solved the problem by changing the file descriptor limit setting.

Environment

  • MacBook Pro 13-inch (2019)
  • macOS Mojave 10.14.5

How to change

Check current settings.

$ launchctl limit
	cpu         unlimited      unlimited
	filesize    unlimited      unlimited
	data        unlimited      unlimited
	stack       8388608        67104768
	core        0              unlimited
	rss         unlimited      unlimited
	memlock     unlimited      unlimited
	maxproc     1418           2128
	maxfiles    256            unlimited

Write the following settings in /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>524288</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>

Reboot MacOS and check current settings.

$ launchctl limit
	cpu         unlimited      unlimited
	filesize    unlimited      unlimited
	data        unlimited      unlimited
	stack       8388608        67104768
	core        0              unlimited
	rss         unlimited      unlimited
	memlock     unlimited      unlimited
	maxproc     1418           2128
	maxfiles    524288         524288
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment