linux查看修改線程默認棧空間大小(ulimit -s)


1.linux查看修改線程默認棧空間大小 ulimit -s

a、通過命令 ulimit -s 查看linux的默認棧空間大小,默認情況下 為10240 即10M

b、通過命令 ulimit -s 設置大小值 臨時改變棧空間大小:ulimit -s 102400, 即修改為100M

c、可以在/etc/rc.local 內 加入 ulimit -s 102400 則可以開機就設置棧空間大小

d、在/etc/security/limits.conf 中也可以改變棧空間大小:

#<domain> <type> <item> <value>

* soft stack 102400

重新登錄,執行ulimit -s 即可看到改為102400 即100M

 

2.為啥csh沒有命令ulimit。
freebsd的默認shell csh的對應內部命令是limit不是ulimit,freebsd還有一個外部命令limits,freebsd中需要改變這些資源使用限制只能用外部命令,內部命令改不了,如果你一定要用ulimit的話,就只能安裝有ulimit內部命令的shell,比如bash,sh

3.ulimit -s限定了用戶應用啟動默認的棧控制大小(僅針對應用主線程;子線程創建時不會像主線程一樣從一個相對固定地址(0X7fffff...)開始,而是需要從堆中切割一塊內存,所以必須指定大小,否則無法獲知要給他分配多大的內存,它的棧內存有主線程創建時可以指定)。

4.為啥linux要限制用戶進程的棧內存大小。

Why does Linux have a default stack size soft limit of 8 MB?

The point is to protect the OS.

Programs that have a legitimate reason to need more stack are rare. On the other hand, programmer mistakes are common, and sometimes said mistakes lead to code that gets stuck in an infinite loop. And if that infinite loop happens to contain a recursive function call, the stack would quickly eat all the available memory. The soft limit on the stack size prevents this: the program will crash but the rest of the OS will be unaffected.

Note that as this is only a soft limit, you can actually modify it from within your program (see setrlimit(2): get/set resource limits) if you really need to.

5.ulimit -s ulimited是啥意思.
ulimited就是不限制
因為主線程內存其實地址固定(0X7fffff...),實際上也就可以看到,主線程地址根本無需限定棧空間大小,它甚至可以將整塊的虛擬內存作為它的棧。

6.cshell中通過unlimit可以將ulimit一些限制取消。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM