新闻  |   论坛  |   博客  |   在线研讨会
linux查看修改线程默认栈空间大小(ulimit -s)
电子禅石 | 2022-01-08 17:50:56    阅读:15517   发布文章

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一些限制取消。

 

ulimit其他功能
1,说明:
ulimit用于shell启动进程所占用的资源.
2,类别:
shell内建命令
3,语法格式:
ulimit [-acdfHlmnpsStvw] [size]
4,参数介绍:
-H 设置硬件资源限制.
-S 设置软件资源限制.
-a 显示当前所有的资源限制.
-c size:设置core文件的最大值.单位:blocks
-d size:设置数据段的最大值.单位:kbytes
-f size:设置创建文件的最大值.单位:blocks
-l size:设置在内存中锁定进程的最大值.单位:kbytes
-m size:设置可以使用的常驻内存的最大值.单位:kbytes
-n size:设置内核可以同时打开的文件描述符的最大值.单位:n
-p size:设置管道缓冲区的最大值.单位:kbytes
-s size:设置堆栈的最大值.单位:kbytes
-t size:设置CPU使用时间的最大上限.单位:seconds
-v size:设置虚拟内存的最大值.单位:kbytes 5,简单实例:


*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
属于自己的技术积累分享,成为嵌入式系统研发高手。
推荐文章
最近访客