大佬教程收集整理的这篇文章主要介绍了再谈Linux的ulimit,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
测试脚本
[[email protected] ~]# cat /tmp/test_ulimit.py import sys def test_n(): @R_318_10586@l=[] try: for i in range(0,100000): @R_318_10586@l.append(open(‘/tmp/{}-{}‘.format(‘jjkkll‘,i),‘w‘)) except Exception as err: print(i,repr(err)) test_n()
关于/etc/security/limit.conf中开篇既有两句话提示
#This file sets the resource limits for the users logged in via PAm. #It does not affect resource limits of the system services.
意思就是这里的限制只对经过PAM验证的登陆用户有效,并明确说明对开机自启的系统服务(经chkconfig 或systemd控制的开机启动服务)以及 /etc/init.d/rc.local(经试验亦无效) 中的命令无效。
另外经验证:同时在/etc/security/limit.conf和/etc/profile中设置不同的值,/etc/profile中的值最终生效(说明PAM认证在profile之前)
首相尝试了在/etc/profile
中添加对应设置,经测试对开机自启的系统服务
和 /etc/init.d/rc.local
仍然无效(并且验证了系统服务的运行时间要早于/etc/init.d/rc.local)
[[email protected] ~]# cat /tmp/log-init (1021,"IOError(24,‘Too many open files‘)") Sat Nov 3 06:35:19 EDT 2018 [[email protected] ~]# cat /tmp/log-rc.local (1021,‘Too many open files‘)") Sat Nov 3 06:35:25 EDT 2018 [[email protected] ~]# ulimit -n 3000 [[email protected] ~]#
而且在/etc/profile中假如ulimit配置(以及任何需要root权限运行的命令),那在以其他用户登陆时,就会报一条“无权限”类错误。是因为 /etc/profile 在系统启动过程中执行的时机:(倒数第一或 第二步)即任何用户登陆前才/先执行/etc/profile,然后再是 ~/.bash_profile(若有的话)
后经查明,/etc/init.d/xxxx 以及/etc/rc.loca中的命令都是centos7之前的产物,centos7之后系统引导及服务管理由sysV改为了systemd,而systemd对于ulimit中指定的各类限制是在xxxx.service文件中设置的,这也是推荐的方式。例如 LimitNOFILE=65536。
/etc/init.d/functions
中增加一句ulimit -n 65536
(以及其他设置)来解决经过实验看下来,发现了一个特点,一个进程能打开的文件描述符总是比设置的nofile值小3,这是因为还有0,1,2 三个标准输入,输出,错误的存在。
以上是大佬教程为你收集整理的再谈Linux的ulimit全部内容,希望文章能够帮你解决再谈Linux的ulimit所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。