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 參考文獻: 1.?http://blackbird.si/checking-limits-of-a-linux-process-ulimit/ 2.?http://stackoverflow.com/questions/34588/how-do-i-change-the-number-of-open-files-limit-in-linux 3.?http://geekswing.com/geek/quickie-tutorial-ulimit-soft-limits-hard-limits-soft-stack-hard-stack/ 4.?http://stackoverflow.com/questions/1356675/check-the-open-fd-limit-for-a-given-process-in-linux 5.?http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/ 6.?http://mcmvp.blog.51cto.com/5497438/1257713 7.?http://www.myexception.cn/linux-unix/436451.html
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 參考文獻: 1.?http://blackbird.si/checking-limits-of-a-linux-process-ulimit/ 2.?http://stackoverflow.com/questions/34588/how-do-i-change-the-number-of-open-files-limit-in-linux 3.?http://geekswing.com/geek/quickie-tutorial-ulimit-soft-limits-hard-limits-soft-stack-hard-stack/ 4.?http://stackoverflow.com/questions/1356675/check-the-open-fd-limit-for-a-given-process-in-linux 5.?http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/ 6.?http://mcmvp.blog.51cto.com/5497438/1257713 7.?http://www.myexception.cn/linux-unix/436451.html
轉載于:https://www.cnblogs.com/Torstan/p/4097638.html
總結
- 上一篇: C++输入cin详解
- 下一篇: 常用个人密码管理软件