1. 程式人生 > >修改程序ulimit限制(不重啟應用)

修改程序ulimit限制(不重啟應用)

文件 brush inf ubuntu port root ubun master ESS

由於線上應用是計費服務,不能重啟,找到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

修改程序ulimit限制(不重啟應用)