How to change default ulimit values in Mac OS X 10.6?

42

14

Mac OS X limits number of processes to 266 and open files to 256. Sometimes this is problem; 256 open files and 266 processes aren't that much.

How it's possible to change default ulimit values in Mac OS X 10.6.7?

(Hopefully there's no difference between 10.6.7 and other Snow Leopard releases.)

Related question in serverfault. Unfortunately, answer is for Mac OS X 10.5, and it's not working in 10.6.

Olli

Posted 2011-03-22T20:00:04.330

Reputation: 6 704

For a quick change: ulimit -n 1024. But it doesn't change the default. – Cœur – 2016-09-23T07:20:11.520

Answers

47

launchctl has control over that now.

You can do a

launchctl limit maxfiles 2048 2048 

to set the soft and hard limits for maximum files open. For more information see the 'limit' section of:

http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/launchctl.1.html

Aaron Kangas

Posted 2011-03-22T20:00:04.330

Reputation: 494

I'm running 10.9.4 and when I launchctl limit maxfiles 2048 2048 and mongo I'm still getting the soft rlimits too low error. Anything else I can try? – Ryan – 2014-07-01T15:04:05.423

after changing the limit with sudo launchctl etc., then close/open the terminal and set the ulimit -n 2048. this time it should work. check it with ulimit -n – chrismarx – 2015-02-06T03:47:03.423

I ran this command and it did something to my Mac. Is it possible to return it to the former setting? – JCraine – 2015-04-17T03:23:26.783

Could someone confirm if 'maxfiles 266 256' will return it to the default? – JCraine – 2015-04-17T03:31:20.357

5After doing 'launchctl limit maxfiles 2048 2048' I got 'too many open files' on my Mac when I tried to do anything in the shell, and Cocoa apps showed empty menus. System was pretty much toasted. A reboot thankfully fixed it. – Graham Wheeler – 2015-10-31T22:06:36.027

4Do not run this command on macOS Sierra. The correct command would be launchctl limit maxfiles 2048 unlimited though I would suggest viewing your current settings with launchctl limit maxfiles before doing so, else you'll completely lock up your computer. – snowe2010 – 2018-05-08T15:55:33.720

1This still works in OS X 10.9 – Olli – 2014-02-16T12:03:53.157

9

There's an answer on StackOverflow for this one. Apparently ulimit does it now.

atl

Posted 2011-03-22T20:00:04.330

Reputation: 101

1You can change values with ulimit, but it's not saving those. Linked post do not include any way to save defaults. – Olli – 2011-04-06T07:22:38.047

3A quick fix: Edit your ~/.bash_profile and add this on a line: ulimit -n 1024 (using whatever number you like, of course) – PapaFreud – 2013-06-12T07:50:36.997

2@PapaFreud That's only executed when you open the terminal/bash. Not all programs are executed from terminal. – Olli – 2014-01-30T14:34:07.463

1

FYI.

.bash_profile update didn't help me for OS v10.10.3, but reinstallation NodeJS from 0.10.35 to 0.12.3 helped me, and error disappear.

Andrii Lundiak

Posted 2011-03-22T20:00:04.330

Reputation: 11