“最大打开文件数”用于工作过程
是否可以增加工作过程的“最大打开文件”参数? 我的意思是这个参数:
cat /proc/<pid>/limits | grep files
谢谢你的建议
Is it possible to increase "Max open files" parameter for working process ?
I mean this parameter:
cat /proc/<pid>/limits | grep files
Thanks for your advices
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
另一种选择是使用 prlimit 命令(来自 util-linux 软件包)。例如,如果要将正在运行的进程的最大打开文件数设置为 4096:
Another option is to use the prlimit command (from the util-linux package). For example if you want to set the maximum number of open files for a running process to 4096:
作为系统管理员:
/etc/security/在大多数 Linux 安装上,limits.conf
文件控制这一点;它允许您设置每个用户的限制。您需要像myuser - nofile 1000
这样的行。在进程内:getrlimit 和 setrlimit 调用 控制大多数每个进程的资源分配限制。
RLIMIT_NOFILE
控制文件描述符的最大数量。您将需要适当的权限才能调用它。As a system administrator: The
/etc/security/limits.conf
file controls this on most Linux installations; it allows you to set per-user limits. You'll want a line likemyuser - nofile 1000
.Within a process: The getrlimit and setrlimit calls control most per-process resource allocation limits.
RLIMIT_NOFILE
controls the maximum number of file descriptors. You will need appropriate permissions to call it.您可以使用 gdb,闯入该进程,调用上述系统调用来提高您感兴趣的限制,然后继续工作并退出 gdb。我已经用这种方式即时编辑了几次。
您的应用程序不会关闭,只是在您执行呼叫时暂时冻结。如果你速度很快(或者你编写了脚本!),它可能不会被注意到。
You could use gdb, break into the process, call the aforementioned syscalls to raise the limit you're interested in, then continue the job and exit gdb. I've edited things on the fly this way a few times.
Your app wouldn't be down, but just frozen for the moment while you performed the call. if you're quick (or you script it!), it'll likely not be noticeable.
...适用于 RHEL5.5 和 RHEL6.7。
请注意,“-n”是强制性的;尾随换行符将生成有关无效参数的投诉。
...works in RHEL5.5 and RHEL6.7.
Note that the "-n" is mandatory; a trailing newline will generate a complaint about invalid arguments.
此链接详细介绍了如何更改此系统范围或每个用户。
This link details how to change this system wide or per user.
是的,可以增加
/proc//limits
中的限制在运行时。只需找到 pid 并执行以下命令:
Yes, it is possible to increase the limits in
/proc/<pid>/limits
at run time. Just find the pid and execute below command:
以下命令给出默认情况下每个进程允许的最大打开文件数限制(分别为软限制和硬限制):
您可以使用程序或命令来更改这些限制。查看 ulimit (man ulimit)。
The following commands give the max # of open files per process permissible by default limits (soft and hard respectively):
You can use a program or a command to change these limits. Look at ulimit (man ulimit).
在 Ubuntu 16.04 上,当 rethinkdb 进程运行时,这些解决方案都不起作用。
我不断收到
错误:accept()失败:打开的文件太多。
最终起作用的是我的
/etc/security/limits.conf
文件中的这个。除了 nofile 之外,请注意 nproc。据我了解,root需要单独指定。您可以通过运行cat /proc/sys/fs/file-max来查看系统最大文件数。我只是将我的设置为在服务器大小合理范围内的最高最大值。
您可以通过运行 cat /proc/{your-pid}/limits 来验证您的进程允许的最大打开文件数。
有用的帖子:https://medium. com/@muhammadtriwibowo/set-permanently-ulimit-n-open-files-in-ubuntu-4d61064429a
On Ubuntu 16.04, with a rethinkdb process running, none of these solutions worked.
I kept getting
error: accept() failed: Too many open files.
What ultimately worked was this in my
/etc/security/limits.conf
file. Note the nproc in addition to the nofile. As I understand it, root needs to specified separately.You can see the system max files by running
cat /proc/sys/fs/file-max
. I just set mine to a high maximum well within reason for the size of the server.You can verify the max open files your process is allowed by running
cat /proc/{your-pid}/limits
.Helpful post: https://medium.com/@muhammadtriwibowo/set-permanently-ulimit-n-open-files-in-ubuntu-4d61064429a