Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to Change Open Files Limit on OS X and macOS Sierra (10.8 - 10.12)

How to Change Open Files Limit on OS X and macOS

This text is the section about OS X Yosemite (which also works for macOS Sierra) from https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/#mac-os-x

The last time i visited this link it was dead (403), so I cloned it here from the latest snapshot in Archive.org's Wayback Machine https://web.archive.org/web/20170523131633/https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/

Mac OS X

To check the current limits on your Mac OS X system, run:

launchctl limit maxfiles

The last two columns are the soft and hard limits, respectively.

Adjusting Open File Limits in Yosemite

To adjust open files limits on a system-wide basis in Mac OS X Yosemite, you must create two configuration files. The first is a property list (aka plist) file in /Library/LaunchDaemons/limit.maxfiles.plist that contains the following XML configuration:

<?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>200000</string>
          <string>200000</string>
        </array>
      <key>RunAtLoad</key>
        <true/>
      <key>ServiceIPC</key>
        <false/>
    </dict>
  </plist>

This will set the open files limit to 200000. The second plist configuration file should be stored in /Library/LaunchDaemons/limit.maxproc.plist with the following contents:

<?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.maxproc</string>
      <key>ProgramArguments</key>
        <array>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxproc</string>
          <string>2048</string>
          <string>2048</string>
        </array>
      <key>RunAtLoad</key>
        <true />
      <key>ServiceIPC</key>
        <false />
    </dict>
  </plist>

Both plist files must be owned by root:wheel and have permissions -rw-r--r--. This permissions should be in place by default, but you can ensure that they are in place by running sudo chmod 644 . While the steps explained above will cause system-wide open file limits to be correctly set upon restart, you can apply them manually by running launchctl limit.

In addition to setting these limits at the system level, we recommend setting the at the session level as well by appending the following lines to your bashrc, bashprofile, or analogous file:

ulimit -n 200000
ulimit -u 2048

Like the plist files, your bashrc or similar file should have -rw-r--r-- permissions. At this point, you can restart your computer and enter ulimit -n into your terminal. If your system is configured correctly, you should see that maxfiles has been set to 200000.

<?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>
<?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.maxproc</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxproc</string>
<string>2048</string>
<string>2048</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
#!/bin/sh
# These are the original gist links, linking to my gists now.
# curl -O https://gist.githubusercontent.com/a2ikm/761c2ab02b7b3935679e55af5d81786a/raw/ab644cb92f216c019a2f032bbf25e258b01d87f9/limit.maxfiles.plist
# curl -O https://gist.githubusercontent.com/a2ikm/761c2ab02b7b3935679e55af5d81786a/raw/ab644cb92f216c019a2f032bbf25e258b01d87f9/limit.maxproc.plist
curl -O https://gist.githubusercontent.com/tombigel/d503800a282fcadbee14b537735d202c/raw/ed73cacf82906fdde59976a0c8248cce8b44f906/limit.maxfiles.plist
curl -O https://gist.githubusercontent.com/tombigel/d503800a282fcadbee14b537735d202c/raw/ed73cacf82906fdde59976a0c8248cce8b44f906/limit.maxproc.plist
sudo mv limit.maxfiles.plist /Library/LaunchDaemons
sudo mv limit.maxproc.plist /Library/LaunchDaemons
sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist
sudo chown root:wheel /Library/LaunchDaemons/limit.maxproc.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist
@devinrhode2

This comment has been minimized.

Copy link

@devinrhode2 devinrhode2 commented Dec 22, 2017

@devinrhode2

This comment has been minimized.

Copy link

@devinrhode2 devinrhode2 commented Dec 22, 2017

However... this answer on SuperUser.com claims that this process of adding a file to Library/LaunchDaemons you describe here is now the way you need to update the file limit for Sierra https://superuser.com/a/1171026/88226

@devinrhode2

This comment has been minimized.

Copy link

@devinrhode2 devinrhode2 commented Dec 28, 2017

@safareli

This comment has been minimized.

Copy link

@safareli safareli commented Jun 20, 2018

YOU SHOULD RESTART YOUR COMPUTER FOR THIS TO WORK

@jiapengjun

This comment has been minimized.

Copy link

@jiapengjun jiapengjun commented Aug 3, 2018

The plist way works well on macOS 10.13.6.
The bashrc/bashprofile way doesn't work even restarting host. "-bash: ulimit: open files: cannot modify limit: Invalid argument" is reported.

@nhelfer

This comment has been minimized.

Copy link

@nhelfer nhelfer commented Aug 8, 2018

If you don't want to restart your computer, you can launch theses commands :
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist

@mjruschak

This comment has been minimized.

Copy link

@mjruschak mjruschak commented Aug 22, 2018

This is great and very helpful. Has anyone been able to get the maxproc limit to stick? I cannot get this one to work but the maxfiles works fine.

@metacritical

This comment has been minimized.

Copy link

@metacritical metacritical commented Oct 10, 2018

Does this work on OSX Mojave?

@centaur1

This comment has been minimized.

Copy link

@centaur1 centaur1 commented Nov 6, 2018

Has anyone tried this on Mojave yet? (to echo @metacritical)

@Larzack

This comment has been minimized.

Copy link

@Larzack Larzack commented Nov 11, 2018

Works

@Larzack

This comment has been minimized.

Copy link

@Larzack Larzack commented Nov 29, 2018

Can't have more than 2048 in maxproc

@swiftyui

This comment has been minimized.

Copy link

@swiftyui swiftyui commented Jan 30, 2019

It works unde Mojave @centaur1

@gautiermichelin

This comment has been minimized.

Copy link

@gautiermichelin gautiermichelin commented Apr 30, 2019

@nhelfer : I used your comment thanks.
Note : add "&&" between the 2 instructions sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist && sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist

@rockkoca

This comment has been minimized.

Copy link

@rockkoca rockkoca commented Jun 14, 2019

if you have ever run this command before and want to change to larger values, be sure to unload them. Otherwise, it will not change.

sudo launchctl unload -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl unload -w /Library/LaunchDaemons/limit.maxproc.plist

Unload before load.

sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist

@jessecarbon

This comment has been minimized.

Copy link

@jessecarbon jessecarbon commented Sep 18, 2019

This doesn't appear to work on 10.15 Catalina beta:

Sep 18 11:44:16 macos1015beta com.apple.xpc.launchd[1] (limit.maxfiles): The ServiceIPC key is no longer respected. Please remove it.

EDIT: Simply removing ServiceIPC from the plist seems to work fine, nevermind!

@alvistar

This comment has been minimized.

Copy link

@alvistar alvistar commented Oct 4, 2019

Hi,
I am on Mojave and I have an issue I can't solve after a lot of googling around.
If I manually unload and load the limit.maxfiles.plist it works, but after a reboot maxfiles will be resetted to 10240.
I suspect there is something else setting that limit during the boot process, but I have no idea how to find it.

Anyone experiencing this problem? Clues?

@hongwei1

This comment has been minimized.

Copy link

@hongwei1 hongwei1 commented Oct 22, 2019

Hi,
I am on Mojave and I have an issue I can't solve after a lot of googling around.
If I manually unload and load the limit.maxfiles.plist it works, but after a reboot maxfiles will be resetted to 10240.
I suspect there is something else setting that limit during the boot process, but I have no idea how to find it.

Anyone experiencing this problem? Clues?

Same for me ... I am Mojave10.14.6. not work in my side

@WeirdCircumstances

This comment has been minimized.

Copy link

@WeirdCircumstances WeirdCircumstances commented Oct 25, 2019

Works for me as described on 10.14. Thanks!

@Bryji

This comment has been minimized.

Copy link

@Bryji Bryji commented Nov 6, 2019

Worked for me on Mojave 10.14.6

@LuckyMagacian

This comment has been minimized.

Copy link

@LuckyMagacian LuckyMagacian commented Nov 8, 2019

Catalina 10.15.1
kern.maxfiles worked but kern.maxproc not
and kern.maxprocperuid was changed howerver I didn't change it !!!!

@StephPeriquet

This comment has been minimized.

Copy link

@StephPeriquet StephPeriquet commented Nov 25, 2019

Both of these :
sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist
sudo launchctl load -w /Library/LaunchDaemons/limit.maxproc.plist
Gives me the following message : /Library/LaunchDaemons/limit.maxfiles.plist: Invalid property list

This even after reboot.

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 10240 10240

Any idea of what to do next?
My issue is coming with adobe Illustrator giving me this error all of the sudden : "Unable to set maximum number of files to be opened", it used to work just fine.
MacMini Mojave 10.14.6

@ledlamp

This comment has been minimized.

Copy link

@ledlamp ledlamp commented Dec 2, 2019

If the launchdaemons are just to run the command launchctl limit maxfiles 200000 then why not just use crontab?

@ledlamp

This comment has been minimized.

Copy link

@ledlamp ledlamp commented Dec 2, 2019

BTW I discovered some things about launchctl limits. If you run launchctl limit maxfiles unlimited it sets it to 10240, even though you can specify a much higher number. While launchctl limit maxproc unlimited does nothing.
And the actual maximums are 2147483647 for maxfiles and 2500 for maxproc.

@ledlamp

This comment has been minimized.

Copy link

@ledlamp ledlamp commented Dec 2, 2019

Apparently setting maxfiles to 2147483647 is not a good idea!! It caused login and lsof (probably others too) to hang at 100% CPU! I couldn't open a terminal because it would hang at login (until timing out after 300 seconds), and Visual Studio Code spawned a ton of lsof's under bash's with grep's, using all CPU, and they orphaned when closing VSC; had to killall lsof.

@flyingfang

This comment has been minimized.

Copy link

@flyingfang flyingfang commented Dec 7, 2019

Catalina 10.15.1
kern.maxfiles worked but kern.maxproc not
and kern.maxprocperuid was changed howerver I didn't change it !!!!

same as you

@plindelauf

This comment has been minimized.

Copy link

@plindelauf plindelauf commented Jan 14, 2020

Is there any working solution for Catalina (10.15.2) yet? I get errors /Library/LaunchDaemons/limit.maxfiles.plist: Invalid property list and /Library/LaunchDaemons/limit.maxproc.plist: Invalid property list even after reboot.

I removed ServiceIPC from the plist as suggested by @jessecarbon, but that does still not work.

@cah-calixtomelean

This comment has been minimized.

Copy link

@cah-calixtomelean cah-calixtomelean commented Jan 30, 2020

Yeah, in Catalina, the use of this file /Library/LaunchDaemons/limit.maxproc.plist is also changing the values for kern.maxfiles and kern.maxfilesperproc. Probably not a good idea.

@plindelauf

This comment has been minimized.

Copy link

@plindelauf plindelauf commented Mar 30, 2020

I was looking for this solution to get rid of frequent "too many open files" and "max file descriptors exceeded" issues. However, since not of the suggested solutions worked on Catalina and I was getting these errors almost daily, I decided to take a more drastic route and perform a completely fresh new Catalina install. And lo and behold: I have been running for three weeks straight without ever encountering a error.

@Windsooon

This comment has been minimized.

Copy link

@Windsooon Windsooon commented Apr 16, 2020

I closed the terminal app and reopen it again then it works.

@nasrulhazim

This comment has been minimized.

Copy link

@nasrulhazim nasrulhazim commented May 4, 2020

nice. it works on Catalina.

Here what basically I did:

$ cd ~
$ nano load.sh

Copy paste this code into the script: https://gist.github.com/tombigel/d503800a282fcadbee14b537735d202c#file-load-sh

$ sudo su
$ cd /Users/<username>
$ . /load.sh
@player1024

This comment has been minimized.

Copy link

@player1024 player1024 commented May 17, 2020

@nas

nice. it works on Catalina.

Here what basically I did:

$ cd ~
$ nano load.sh

Copy paste this code into the script: https://gist.github.com/tombigel/d503800a282fcadbee14b537735d202c#file-load-sh

$ sudo su
$ cd /Users/<username>
$ . /load.sh

does this have to be executed every time we log in?
when I run launchctl limit I still get 10240 max files....
if I try to manually rerun the load.sh, I get the following:
/Library/LaunchDaemons/limit.maxfiles.plist: service already loaded
/Library/LaunchDaemons/limit.maxproc.plist: service already loaded

@nasrulhazim

This comment has been minimized.

Copy link

@nasrulhazim nasrulhazim commented May 18, 2020

@nas

nice. it works on Catalina.
Here what basically I did:

$ cd ~
$ nano load.sh

Copy paste this code into the script: https://gist.github.com/tombigel/d503800a282fcadbee14b537735d202c#file-load-sh

$ sudo su
$ cd /Users/<username>
$ . /load.sh

does this have to be executed every time we log in?
when I run launchctl limit I still get 10240 max files....
if I try to manually rerun the load.sh, I get the following:
/Library/LaunchDaemons/limit.maxfiles.plist: service already loaded
/Library/LaunchDaemons/limit.maxproc.plist: service already loaded

I just ran it once.

@player1024

This comment has been minimized.

Copy link

@player1024 player1024 commented May 18, 2020

@nas

nice. it works on Catalina.
Here what basically I did:

$ cd ~
$ nano load.sh

Copy paste this code into the script: https://gist.github.com/tombigel/d503800a282fcadbee14b537735d202c#file-load-sh

$ sudo su
$ cd /Users/<username>
$ . /load.sh

does this have to be executed every time we log in?
when I run launchctl limit I still get 10240 max files....
if I try to manually rerun the load.sh, I get the following:
/Library/LaunchDaemons/limit.maxfiles.plist: service already loaded
/Library/LaunchDaemons/limit.maxproc.plist: service already loaded

I just ran it once.

when you ran launchctl limit after restart how many maxfiles did it return? also what is you macos version? did you do any other modifications for this to work? (like kerntex files etc). thank you

@nasrulhazim

This comment has been minimized.

Copy link

@nasrulhazim nasrulhazim commented May 21, 2020

launchctl limit

maxfiles 524288 524288

@dredhorse

This comment has been minimized.

Copy link

@dredhorse dredhorse commented May 26, 2020

@swineone

This comment has been minimized.

Copy link

@swineone swineone commented Jun 6, 2020

Getting this error in Catalina (10.15.4) in system.log, which means the limits are unchanged after reboot -- I have to manually unload and load again every time I reboot the computer -- any ideas?

Jun  6 00:51:26 xxxxx com.apple.xpc.launchd[1] (com.apple.xpc.launchd.domain.system): Caller not allowed to perform action: launchctl.686, action = modify rlimits, code = 1: Operation not permitted, uid = 501, euid = 501, gid = 20, egid = 20, asid = 100006
Jun  6 00:51:26 xxxxx com.apple.xpc.launchd[1] (limit.maxfiles[686]): Service exited with abnormal code: 1
@viggys

This comment has been minimized.

Copy link

@viggys viggys commented Jun 29, 2020

WORKING SOLUTION FOR CATALINA 10.15.5 !!

This solution seems to be easy, neat and working for Catalina 10.15.5,

launchctl limit maxfiles <LIMIT>
https://apple.stackexchange.com/questions/366187/why-does-setting-the-hard-limit-for-maxfiles-to-unlimited-using-launchctl-lim

Restart was not required.

@phylaxis

This comment has been minimized.

Copy link

@phylaxis phylaxis commented Jul 2, 2020

Hey @viggys that solution doesn't seem really viable because once you use that command it removes "unlimited" from the Hard limit and then you can never get it back.

@viggys

This comment has been minimized.

Copy link

@viggys viggys commented Jul 2, 2020

Hey @phylaxis, agree that the command removes the"unlimited" from the hard limit and never get it back. As per the analysis in https://apple.stackexchange.com/a/366319 it's mentioned that the value of unlimited can be upto the max value of SIGNED INT, which is 2147483647.

So by losing unlimited, we can work around by setting a specific value for the HARD LIMIT which is less than 2147483647.

@viggys

This comment has been minimized.

Copy link

@viggys viggys commented Jul 2, 2020

Hey @viggys that solution doesn't seem really viable because once you use that command it removes "unlimited" from the Hard limit and then you can never get it back.

Hey @phylaxis, just got to realise that restarting my mac has set back the default limits

Screenshot 2020-07-02 at 7 02 40 PM

So, the launchctl limit maxfiles <LIMIT> set the limits temporarily, which i think is a fair solution.

@evandrix

This comment has been minimized.

Copy link

@evandrix evandrix commented Jul 19, 2020

typo in README - one fewer /: <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

@gmahe

This comment has been minimized.

Copy link

@gmahe gmahe commented Jul 27, 2020

Works on Catalina 10.15.6, just make sure you are in /Library/LaunchDaemons/ and not ~/Library/LaunchDaemons/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.