“最大打开文件数”用于工作过程

发布于 2024-09-19 15:48:03 字数 123 浏览 3 评论 0原文

是否可以增加工作过程的“最大打开文件”参数? 我的意思是这个参数:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

冷弦 2024-09-26 15:48:03

另一种选择是使用 prlimit 命令(来自 util-linux 软件包)。例如,如果要将正在运行的进程的最大打开文件数设置为 4096:

prlimit -n4096 -p pid_of_process

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:

prlimit -n4096 -p pid_of_process

诗化ㄋ丶相逢 2024-09-26 15:48:03

作为系统管理员/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 like myuser - 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.

浅笑轻吟梦一曲 2024-09-26 15:48:03

您可以使用 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.

入画浅相思 2024-09-26 15:48:03
echo -n "Max open files=20:20" > /proc/$pid/limits

...适用于 RHEL5.5 和 RHEL6.7。

请注意,“-n”是强制性的;尾随换行符将生成有关无效参数的投诉。

echo -n "Max open files=20:20" > /proc/$pid/limits

...works in RHEL5.5 and RHEL6.7.

Note that the "-n" is mandatory; a trailing newline will generate a complaint about invalid arguments.

乖乖公主 2024-09-26 15:48:03

此链接详细介绍了如何更改此系统范围每个用户

许多应用程序如 Oracle 数据库或 Apache Web 服务器需要
这个范围相当高。所以你可以增加最大数量
通过在内核变量中设置新值来打开文件
/proc/sys/fs/file-max如下(以root身份登录):

$ sysctl -w fs.file-max=100000

您需要编辑 /etc/sysctl.conf 文件并添加以下行,以便重新启动后设置保持不变

This link details how to change this system wide or per user.

Many application such as Oracle database or Apache web server needs
this range quite higher. So you can increase the maximum number of
open files by setting a new value in kernel variable
/proc/sys/fs/file-max as follows (login as the root):

$ sysctl -w fs.file-max=100000

You need to edit /etc/sysctl.conf file and put following line so that after reboot the setting will remain as it is

ぺ禁宫浮华殁 2024-09-26 15:48:03

是的,可以增加 /proc//limits 中的限制
在运行时。只需找到 pid 并执行以下命令:

echo -n "Max open files=20:20" > /proc/$pid/limits

Yes, it is possible to increase the limits in /proc/<pid>/limits
at run time. Just find the pid and execute below command:

echo -n "Max open files=20:20" > /proc/$pid/limits
烟若柳尘 2024-09-26 15:48:03

以下命令给出默认情况下每个进程允许的最大打开文件数限制(分别为软限制和硬限制):

ulimit -Sa
ulimit -Ha

您可以使用程序或命令来更改这些限制。查看 ulimit (man ulimit)。

The following commands give the max # of open files per process permissible by default limits (soft and hard respectively):

ulimit -Sa
ulimit -Ha

You can use a program or a command to change these limits. Look at ulimit (man ulimit).

眸中客 2024-09-26 15:48:03

在 Ubuntu 16.04 上,当 rethinkdb 进程运行时,这些解决方案都不起作用。

我不断收到错误:accept()失败:打开的文件太多。

最终起作用的是我的/etc/security/limits.conf文件中的这个。除了 nofile 之外,请注意 nproc。据我了解,root需要单独指定。

*                soft    nofile          200000
*                hard    nofile          1048576
root             soft    nofile          200000
root             hard    nofile          1048576
*                soft    nproc           200000
*                hard    nproc           1048576
root             soft    nproc           200000
root             hard    nproc           1048576

您可以通过运行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.

*                soft    nofile          200000
*                hard    nofile          1048576
root             soft    nofile          200000
root             hard    nofile          1048576
*                soft    nproc           200000
*                hard    nproc           1048576
root             soft    nproc           200000
root             hard    nproc           1048576

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文