在Linux上-将最大打开文件数设置为无限制.可能的? [英] On Linux - set maximum open files to unlimited. Possible?

查看:581
本文介绍了在Linux上-将最大打开文件数设置为无限制.可能的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将打开文件的最大数量设置为某个无限"值,或者必须为一个数字?

我需要将守护程序用户的描述符限制设置为无限制",我试图确定这是否可行或如何实现.我已经看到一些邮件列表引用了可以使用的最大值"值(例如:"myuser hard nofile max",但是到目前为止,我参考的手册页和参考文献都没有对此进行支持. >

如果我不能使用'max'或类似的东西,我想知道如何(理论上)确定最大文件数,因此我为选择的任何数量都有一定的依据.如果有更合理的方法来获得上限,我不想使用100000000或其他值.

如果重要,我正在使用RHEL 5.

更新:在撰写问题时,我是个白痴.理想情况下,我想在limits.conf文件中执行此操作(这是"max"的来源).这会改变答案吗?


感谢您的评论.这是针对JBOSS实例而不是我正在编写的守护程序的,因此我不知道setrlimit()是否对我有用.但是,Jefromi-我喜欢Infinity的定义:)我看到一篇帖子建议文件描述符为两个短裤和一个指针",因此我应该能够计算出近似的上限.

解决方案

POSIX允许您使用

I had a requirement to set the descriptor limit for a daemon user to be "unlimited" and I'm trying to determine if that's possible or how to do it. I've seen some mailing lists refer to a "max" value that can be used (as in: "myuser hard nofile max", but so far the man pages and references I've consulted don't back that up.

If I can't use 'max' or similar, I'd like to know how to determine what the max number of files is (theoretically) so I have some basis for whatever number I pick. I don't want to use 100000000 or something if there's a more reasonable way to get an upper bound.

I'm using RHEL 5 if it's important.

Update: I'm an idiot when it comes to writing questions. Ideally I'd like to do this in the limits.conf file (which is where "max" would come from). Does that change any answers?


Thanks for the comments. This is for a JBOSS instance and not a daemon I'm writing so I don't know if setrlimit() is useful to me. However, Jefromi - I do like the definition of Infinity :) I saw a post that suggests a file descriptor is "two shorts and a pointer" so I should be able to calculate the approximate upper bound.

解决方案

POSIX allows you to set the RLIMIT_NOFILE resource limit to RLIM_INFINITY using setrlimit(). What this means is that the system will not enforce this resource limit. Of course, you will still be limited by the implementation (e.g. MAXINT) and any other resource limitations (e.g. available memory).

Update: RHEL 5 has a maximum value of 1048576 (220) for this limit (NR_OPEN in /usr/include/linux/fs.h), and will not accept any larger value including infinity, even for root. So on RHEL 5 you can use this value in /etc/security/limits.conf and that is as close as you are going to get to infinity.

Not long ago a Linux kernel patch was applied to allow this limit to be set to infinity, however it has since been reverted as a result of unintended consequences.

这篇关于在Linux上-将最大打开文件数设置为无限制.可能的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆