1、ulimit
set or get the shells resource usage limits
ulimit [OPTIONS] [LIMIT]
2、option
① -a 顯示目前所有的資源限制。
② -c size:設定core檔案的最大值。機關:blocks
③ -n size 指定同一時間最多可開啟的檔案數
④ -l size:設定在記憶體中鎖定程序的最大值。機關:KB
⑤ -m size:設定可以使用的常駐記憶體的最大值。機關:KB
⑥ -s size:設定堆棧的最大值。機關:kbytes
⑦ -t size:設定CPU使用時間的最大上限。機關:seconds
⑧ -v size:設定虛拟記憶體的最大值。機關:kbytes
3、示例
1)ulimit -s 262140 //設定堆棧的最大值為256M,預設為10M
通過/etc/profile或/.bash_profile中添加該指令來使系統記住該值
source /root/.bash_profile
/etc/security/limits 對這些值進行了定義
2)ulimit -u 10000 //使用者的最大程序數
3)ulimit -n 4096 //将每個程序可以打開的檔案數目設定為4096
4)其他建議設定成無限制(unlimited)的一些重要設定是:
① 資料段長度:ulimit -d unlimited
② 最大記憶體大小:ulimit -m unlimited
③ 堆棧大小:ulimit -s unlimited
④ CPU 時間:ulimit -t unlimited
⑤ 虛拟記憶體:ulimit -v unlimited
⑥ core檔案大小 ulimit -c unlimited/size
說明:
檔案cat /proc/sys/kernel/core_pattern/ 記錄當下core檔案的位置,core則為目前目錄。
5)通過ulimit可以對程序和使用者分别做資源限制了。很多應用需要對整個系統的資源使用做一個總的限制,這時候我們需要修改 /proc 下的配置檔案。
/proc 目錄下包含了很多系統目前狀态的參數,例如 /proc/sys/kernel/pid_max。
4、C語言中的ulimit,get and set user limits。[5]
參考
【2】 更多參數的叙述
<a href="http://linux.die.net/man/1/ulimit">http://linux.die.net/man/1/ulimit</a>
<a href="http://zhangyafeng0917.blog.163.com/blog/static/44436412201082921948750/">http://zhangyafeng0917.blog.163.com/blog/static/44436412201082921948750/</a>
【3】 講解了幾個應用場景
<a href="http://www.justwinit.cn/post/2650/">http://www.justwinit.cn/post/2650/</a>
【4】 舉了很多應用執行個體
<a href="http://hi.baidu.com/fengjian1585/blog/item/b49aa7a232f1f1b9cbefd023.html">http://hi.baidu.com/fengjian1585/blog/item/b49aa7a232f1f1b9cbefd023.html</a>