更改 Linux 系统进程可以打开的文件描述符数量限制是通过修改 /etc/security/limits.conf
来实现的,通过以下命令,打开配置文件。
sudo gedit /etc/security/limits.conf
然后在打开的文件中添加并保存以下两行内容:
* soft nofile 65535
* hard nofile 65535
最后,重启系统。通过 ulimit -n
可以看到文件描述符数量限制。
然而,我在 Ubuntu18.04 及以后的版本中使用上述步骤并没有生效,经过搜索可知,需要在 /etc/systemd/user.conf
和 /etc/systemd/system.conf
文件的末尾添加如下内容:
DefaultLimitNOFILE=65535
并且同样执行之前的修改 /etc/security/limits.conf
的操作,才能生效。
不过,这种方法似乎对WSL不生效。
参考:https://blog.csdn.net/u010312474/article/details/108666734