由于线上应用是计费服务,不能重启,找到2种动态修改程序ulimits限制的方法。
方法一:prlimit工具修改
方法二:python3+ resource模块
下面举例修改nginx的core file大小限制
#找出nginx进程 root@VM-131-5-ubuntu:/etc/security# ps -ef |grep nginx root 16436 1 0 13:01 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 16439 16436 0 13:01 ? 00:00:00 nginx: worker process root 16527 14045 0 13:01 pts/0 00:00:00 grep --color=auto nginx #找到进程的core文件大小限制 root@VM-131-5-ubuntu:/etc/security# cat /proc/16436/limits |grep core Max core file size 0 unlimited bytes #利用python3 resource模块修改core文件大小限制 root@VM-131-5-ubuntu:/etc/security# python3 Python 3.4.3 (default, Nov 12 2018, 22:25:49) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import resource >>> resource.prlimit(16436,resource.RLIMIT_CORE,(-1,-1)) (0, -1) >>> exit() #再次查看该nginx进程的core文件大小限制 root@VM-131-5-ubuntu:/etc/security# cat /proc/16436/limits |grep core Max core file size unlimited unlimited bytes
原文:https://www.cnblogs.com/xingxiz/p/10364706.html