MacOS出现/usr/bin/ulimit: line 4: ulimit: open files: cannot modify limit: Invalid argument解决方案

症状

1
2
$ sudo ulimit -n 65535
/usr/bin/ulimit: line 4: ulimit: open files: cannot modify limit: Invalid argument

解决方案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
➜  ~ echo kern.maxfiles=65535 | sudo tee -a /etc/sysctl.conf
Password:
kern.maxfiles=65535
➜ ~ echo kern.maxfilesperproc=65535 | sudo tee -a /etc/sysctl.conf
kern.maxfilesperproc=65535
➜ ~ sudo sysctl -w kern.maxfiles=65535
kern.maxfiles: 12288 -> 65535
➜ ~ sudo sysctl -w kern.maxfilesperproc=65535
kern.maxfilesperproc: 10240 -> 65535
➜ ~ ulimit -n 65535 65535
➜ ~ ulimit -a
-t: cpu time (seconds) unlimited
-f: file size (blocks) 65535
-d: data seg size (kbytes) unlimited
-s: stack size (kbytes) 8192
-c: core file size (blocks) 0
-v: address space (kbytes) unlimited
-l: locked-in-memory size (kbytes) unlimited
-u: processes 709
-n: file descriptors 65535
➜ ~

Via: http://blog.mact.me/2014/10/22/yosemite-upgrade-changes-open-file-limit

可以把 ulimit -n 65536 65536 加入到 ~/.bash_profile中以免每次修改。