3

I'm running El Capitan / Mac OSX 10.11.6 (15G1108) and I want to increase the "Max Open files" for some of my terminals / bash sessions. I'm logged in with my normal users. I read through all the guides I could find and managed to increase some limits:

As my user:

$ launchctl limit maxfiles
    maxfiles    200000         200000        

But, when I try to set the limit, I fail:

$ ulimit -n 8096
-bash: ulimit: open files: cannot modify limit: Operation not permitted

The strange thing is that I actually can set the ulimit if I switch to root:

$ sudo bash
$ ulimit -n 9086

Now of course, running everything as root is stupid, so I'm searching for a better solution. How can I allow my user to also increase his "Max Files Limit"?

What I have done already:

$ cat /etc/sysctl.conf
kern.maxfiles=65536
kern.maxfilesperproc=65536

$ 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>200000</string>
          <string>200000</string>
        </array>
      <key>RunAtLoad</key>
        <true/>
      <key>ServiceIPC</key>
        <false/>
    </dict>
  </plist>
  • Hmm, strange: in my ElCap VM every user can change the open files limit with ulimit -n *. – klanomath Dec 21 '16 at 15:58
1

Having had this exact same problem, I ultimately found that my bash startup sequence (.bashrc or similar) was doing a ulimit -n 1024; and that caused both the soft and the hard limit to get set; the latter of which prevented any attempt at raising it afterwards, giving rise to the "bash: ulimit: open files: cannot modify limit: Operation not permitted" error.

So, removing that command got the soft and hard limits restored to the apparent system defaults of 256 and unlimited respectively. The latter is what will enable you to ulimit -n <whatever> again.

In your case, assuming the cause is similar and your Library/LaunchDaemons/limit.maxfiles.plist is still in place as listed, I expect that ulimit -Sn and ulimit -Hn will report both to be 200000.

0

For me on macOS Mojave, I had to set both:

.bash_profile

ulimit -n 65536

.bashrc

ulimit -n 65536

If you only set from profile you can only increase from 256 to 1024.

It’s weird because there is not so much info about this online, I wonder how developers manage without it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .