Skip navigation

This will be a quick post. Working with a stress test tool, I realized that most of the tests were failing due to the “too many files open” error from the Mac OS X. Immediately figure out that Mac OS X comes with the 256 as the default limit for the number of the files open by a single process. This would be ok for most of the users but what about developers which usually works with a test environment on their own machine?

Launchd is the daemon responsible for managing process. It also controls some of the processes limit information (soft and hard limits for open files, max number of child processes, so on…). The solution is to make use of the launchctl tool from the command line and create the launchd.conf file for the persistent change. Open your Terminal and type the following commands:

sudo echo “limit maxfiles 1000000 1000000” > /etc/launchd.conf

launchctl limit maxfiles 1000000 1000000

Note for Programmers:

Programs utilizing I/O multiplex or non-blocking I/O on Mac OS X are by default restricted to 1024 file descriptors per process. In order to overcome this limitation you can either re-define FD_SETSIZE macro (before you include <sys/types.h> or to limit the maxfiles to 1024. This will make the warning messages disappear during the compilation time.

6 Comments

  1. Sorry to bother you with a silly question… I’m not a Unix geek and I just would like to use the script to let my online backup override that files limit (it is Java based and looks like that it is causing it to stop when reached). Unfortunately when I execute the command, even as root, the system tell me that launchd.conf is a read-only file and can’t be modified. How can I fix it? Thanks a lot

  2. Its me again. I’ve done by myself… and everything works fine. Thanks a lot for the hint! It has really saved my day!
    antonio

    • Hi Antonio, Glad that helped you. Sorry for not replying you earlier…. long time that I don’t check my blog. Will try to keep it more up-to-date.
      Best Regards,
      Daniel Froz

  3. Be sure to do an append to launchd.conf using the double >>
    >> /etc/launchd.conf
    and not an overwrite as other apps may use launchd.conf (i.e. google’s stuff).

  4. On some macs it limited to 128 by default.

  5. Hi!
    I tried those two lines in Terminal, but the first command gives an error: “-bash: /etc/launchd.conf: Permission denied”.
    I guess it’s not okay? I have administrative rights on my user account.
    Is it so, that the whole line should be written? I mean:
    sudo echo “limit maxfiles 1000000 1000000″ > /etc/launchd.conf

    The second line works fine, but maybe it hasn’t any effect if the first doesn’t do anything.
    This is quite old topic here, and maybe the OS has changed in between. I’m using OS X 10.6.8.

    Thanks for any help!


2 Trackbacks/Pingbacks

  1. […] Thanks Usr Inapto!  This was his solution. […]

  2. […] for me, and I had plenty of RAM and disk space, so what gives? It turns out that – from this handy post – Snow Leopard only allows each process to have a maximum of 256 files open at any one […]

Leave a comment