file-max和ulimit

http://tommwq.tech/blog/2020/11/04/182

file-max的含义

通过man proc,可得到file-max的描述:

This file defines a system-wide limit on the number of open files for all processes. (See also setrlimit(2), which can be used by a process to set the per-process limit, RLIMIT_NOFILE, on the number of files it may open.) If you get lots of error messages about running out of file handles, try increasing this value:

从这里可以知道,file-max是设置系统所有进程总共可以打开的文件数量。如果得到大量使用完文件描述符的错误信息,是应该增加这个值。

如果要临时性修改file-max的值,可以执行下列命令

echo 6553560 > /proc/sys/fs/file-max

如果要永久性修改file-max,打开文件/etc/sysctl.conf, 加入

fs.file-max = 6553560

重启系统后生效。

除了全局的file-max限制,程序可以通过setrlimit函数,设置单个进程的文件描述符数量限制。

ulimit

同样的,先看man

Provides control over the resources available to the shell and to processes started by it, on systems that allow such control.

ulimit是当前shell以及由它启动的进程的资源限制。系统默认的ulimit对文件打开数量的限制是1024,修改/etc/security/limits.conf文件可以调整这一配置。

soft nofile 65535

hard nofile 65535

修改完之后,重启即可生效。

对于服务器,file-max和ulimit都需要进行配置,否则容易出现文件描述符用尽的情况。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值