Answers:
如果您的过程是通过脚本启动的,则可以在执行守护程序之前将对ulimit的调用放置在脚本中。
如果您希望增加用户或所有用户的ulimit,则可以设置pam_limits登录时通过应用的限制。这些设置在中/etc/security/limits.conf。就您而言,您可以执行以下操作:
*               hard    nofile             2048
请注意,“硬”表示硬限制-不能超过且不能更改的限制。用户(例如,没有root能力的用户)可以更改软限制,但不能超出硬限制。
阅读以limits.conf获得有关使用的更多信息pam_limits。
内核中还有一个打开文件的“最大总数”,您可以使用以下命令检查当前设置:
cat /proc/sys/fs/file-max 
并使用以下参数设置新值:
echo "104854" > /proc/sys/fs/file-max
如果要保留两次重启之间的配置,请添加
sys.fs.file-max=104854
至
/etc/sysctl.conf
要检查当前最大文件使用量:
[root@srv-4 proc]# cat /proc/sys/fs/file-nr
3391    969     52427
|        |       |
|        |       |
|        |       maximum open file descriptors
|        total free allocated file descriptors
total allocated file descriptors
(the number of file descriptors allocated since boot)
0,则仅表示分配的文件句柄数与使用的文件句柄数完全匹配。
                    49152	0	18446744073709551615 。我不明白为什么前两列加起来不等于第三列。如果我有1.8万亿亿美元可用,我不知道如何使用它们。
                    这取决于您如何开始长时间运行的过程。如果它是在引导时启动的(通过/etc/rcX.d/*脚本),那么您必须在启动脚本中放置一个ulimit调用,因为默认限制是由内核设置的,并且如果不重新编译它是不可调整的。
/etc/security/limits.conf如果您使用cron例如这样的条目来启动它,则使用可以工作:
@reboot $HOME/bin/my-program
那应该起作用,因为/etc/pam.d/cron启用了pam_limits.so。
您可以在/etc/security/limits.conf中添加它
root soft nofile 100000
root hard nofile 100000
保存然后重新启动。
一个非常好的命令是,ulimit -n但是存在连接过多和打开文件过多的问题:
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 519357
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
ulimit -a,不是ulimit -n。