zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    非循环单链表节点的操作
    链表每一个节点的数据类型该如何表示
    链表的定义、确定一个链表需要几个参数?
    typedef的用法
    连续存储数组的算法(包含数组倒置、冒泡排序……)
    跨函数使用内存案例
    malloc()动态分配内存概述
    结构体
    指针和数组
    C#基础知识之dnSpy反编译
  • 原文地址:https://www.cnblogs.com/Peter2014/p/7883259.html
Copyright © 2011-2022 走看看