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.為啥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.


免責聲明!

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



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