linux偶尔遇到gradle 编译时, 发生"Too many open files" 导致编译失败.
网上说了一堆 ulimit的, 不顶用. 以下方法 实测有用.
参考:
https://superuser.com/questions/1200539/cannot-increase-open-file-limit-past-4096-ubuntu
// 操作步骤:
$ sudo gedit /etc/security/limits.conf
// 1> 文件末尾加上这个在末尾:
* - nofile 65535
// 2> 创建/etc/systemd/system.conf.d/limits.conf, 并增加内容
sudo mkdir /etc/systemd/system.conf.d
sudo touch /etc/systemd/system.conf.d/limits.conf
sudo vim /etc/systemd/system.conf.d/limits.conf
这放到这个文件去:
[Manager]
DefaultLimitNOFILE=65535
// 3> 最后
systemctl daemon-reexec
然后重启电脑.
最后 随便弄一个进程 cat /proc/[pid]/limits 可以看到到"Max open files"变为 65535
$ cat /proc/3212/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 192492 192492 processes
Max open files 65535 65535 files
Max locked memory 16777216 16777216 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 192492 192492 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us