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.

原文地址:https://www.cnblogs.com/Peter2014/p/7883259.html