ulimit小结

1. limits是一个进程的资源,会被子进程继承
 
2. soft limit -S, hard limits -H
hard limits只能被root用户修改,启动的时候会加载配置/etc/security/limits.conf
soft limits可以被任何用户修改,但不能超过hard limits
 
3. 在linux下,每个进程的limit信息保存在/proc/PID/limits文件中(linux OS kenerl > 2.6.24)。低于2.6.24版本的kenerl需要手动统计 /proc/PID/fd下面有多个少个文件。
 
4. lsof -p pid显示所有的打开文件包括shared library
lsof 会统计一些duplicate的open file
 
5. system-wide fd
sysctl -a
vim /etc/sysctl.conf
 
6. max open file on the system
cat /proc/sys/fs/file-max
 
7. stat the openning file from the kenerl point of view
cat /proc/sys/fs/file-nr 
864     0       3274116
have 864 out of max
3274116 open files


8.利用lsof统计每个进程打开的文件数目
lsof -n |awk '{print $2}'|sort|uniq -c |sort -nr|more 

9. 设置普通用户下打开文件的最大值
 ulimit -n 4096
-bash: ulimit: open files: cannot modify limit: Operation not permitted
9.1 在/etc/security/limits.conf中添加
* hard nofile 100000
* soft nofile 100000
9.2 /etc/pam.d/login 添加
session required     /lib64/security/pam_limits.so
9.3 重启 ssh2和rccron,这样只进程就自动继承了nofile
/etc/init.d/ssh2 restart
rccron restart
 
 
 
参考文献:
原文地址:https://www.cnblogs.com/Torstan/p/4097638.html