问题描述
运行应用程序时,有时会出现关于too many files open
的错误.
When running my application I sometimes get an error about too many files open
.
运行ulimit -a
报告限制为1024.如何将限制增加到1024以上?
Running ulimit -a
reports that the limit is 1024. How do I increase the limit above 1024?
修改ulimit -n 2048
导致权限错误.
推荐答案
您始终可以尝试执行ulimit -n 2048
.这只会重置当前shell的限制,并且您指定的数字不得超过硬限制
You could always try doing a ulimit -n 2048
. This will only reset the limit for your current shell and the number you specify must not exceed the hard limit
每个操作系统在配置文件中都有不同的硬限制设置.例如,可以在从/etc/system引导时设置Solaris上的硬打开文件限制.
Each operating system has a different hard limit setup in a configuration file. For instance, the hard open file limit on Solaris can be set on boot from /etc/system.
set rlim_fd_max = 166384
set rlim_fd_cur = 8192
在OS X上,必须在/etc/sysctl.conf中设置相同的数据.
On OS X, this same data must be set in /etc/sysctl.conf.
kern.maxfilesperproc=166384
kern.maxfiles=8192
在Linux下,这些设置通常位于/etc/security/limits.conf中.
Under Linux, these settings are often in /etc/security/limits.conf.
有两种限制:
- 软限制只是当前强制执行的限制
- 硬限制标记了通过设置软限制不能超过的最大值
- soft limits are simply the currently enforced limits
- hard limits mark the maximum value which cannot be exceeded by setting a soft limit
任何用户都可以设置软限制,而硬限制只能由root用户更改.限制是流程的属性.它们是在创建子进程时继承的,因此应在系统初始化期间在init脚本中设置系统范围的限制,并应在用户登录期间设置用户限制(例如,使用pam_limits).
Soft limits could be set by any user while hard limits are changeable only by root.Limits are a property of a process. They are inherited when a child process is created so system-wide limits should be set during the system initialization in init scripts and user limits should be set during user login for example by using pam_limits.
机器启动时通常会设置默认值.因此,即使您可以在单个shell中重置ulimit,也可能会发现它在重新引导时重置为先前的值.如果要更改默认值,则可能需要为存在ulimit命令grep您的引导脚本.
There are often defaults set when the machine boots. So, even though you may reset your ulimit in an individual shell, you may find that it resets back to the previous value on reboot. You may want to grep your boot scripts for the existence ulimit commands if you want to change the default.
这篇关于如何更改Linux中打开文件的数量限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!