博客專欄

EEPW首頁 > 博客 > linux查看修改線程默認(rèn)??臻g大小(ulimit -s)

linux查看修改線程默認(rèn)??臻g大?。╱limit -s)

發(fā)布人:電子禪石 時間:2022-01-08 來源:工程師 發(fā)布文章
linux查看修改線程默認(rèn)??臻g大小(ulimit -s)

1.linux查看修改線程默認(rèn)??臻g大小 ulimit -s

a、通過命令 ulimit -s 查看linux的默認(rèn)??臻g大小,默認(rèn)情況下 為10240 即10M

b、通過命令 ulimit -s 設(shè)置大小值 臨時改變??臻g大?。簎limit -s 102400, 即修改為100M

c、可以在/etc/rc.local 內(nèi) 加入 ulimit -s 102400 則可以開機(jī)就設(shè)置??臻g大小

d、在/etc/security/limits.conf 中也可以改變??臻g大?。?/p>

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

* soft stack 102400

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

 

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

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

4.為啥linux要限制用戶進(jìn)程的棧內(nèi)存大小。

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就是不限制
因?yàn)橹骶€程內(nèi)存其實(shí)地址固定(0X7fffff...),實(shí)際上也就可以看到,主線程地址根本無需限定??臻g大小,它甚至可以將整塊的虛擬內(nèi)存作為它的棧。

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

 

ulimit其他功能
1,說明:
ulimit用于shell啟動進(jìn)程所占用的資源.
2,類別:
shell內(nèi)建命令
3,語法格式:
ulimit [-acdfHlmnpsStvw] [size]
4,參數(shù)介紹:
-H 設(shè)置硬件資源限制.
-S 設(shè)置軟件資源限制.
-a 顯示當(dāng)前所有的資源限制.
-c size:設(shè)置core文件的最大值.單位:blocks
-d size:設(shè)置數(shù)據(jù)段的最大值.單位:kbytes
-f size:設(shè)置創(chuàng)建文件的最大值.單位:blocks
-l size:設(shè)置在內(nèi)存中鎖定進(jìn)程的最大值.單位:kbytes
-m size:設(shè)置可以使用的常駐內(nèi)存的最大值.單位:kbytes
-n size:設(shè)置內(nèi)核可以同時打開的文件描述符的最大值.單位:n
-p size:設(shè)置管道緩沖區(qū)的最大值.單位:kbytes
-s size:設(shè)置堆棧的最大值.單位:kbytes
-t size:設(shè)置CPU使用時間的最大上限.單位:seconds
-v size:設(shè)置虛擬內(nèi)存的最大值.單位:kbytes 5,簡單實(shí)例:


*博客內(nèi)容為網(wǎng)友個人發(fā)布,僅代表博主個人觀點(diǎn),如有侵權(quán)請聯(lián)系工作人員刪除。

led顯示器相關(guān)文章:led顯示器原理




關(guān)鍵詞: linux

相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉