linux 進程的最大線程個數
來源:程序員人生 發布時間:2015-01-20 08:11:24 閱讀次數:3624次
1. 可以通過下面的方法查到:
cat /proc/sys/kernel/threads-max
15882
另外,1個進程實際的線程個數,可以從 /proc/{PID}/status里得出:
/proc/544#cat status
Name: kpsmoused
State: S (sleeping)
Tgid: 544
Pid: 544
PPid: 2
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 32
Groups:
<strong>Threads: 1</strong>
SigQ: 0/7941
2。這個最大個數是在函數 fork_init 里算出來的:
/*
* The default maximum number of threads is set to a safe
* value: the thread structures can take up at most half
* of memory.
*/
max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE);
#define THREAD_SIZE 8192
mempages 是物理內存的大小(以頁面為單位)。可以用以下方法查到:
cat /proc/zoneinfo | grep spanned | awk '{totalpages=totalpages+$2
} END {print totalpages}'
THREAD_SIZE為線程的棧大小。可以用 ulimit 查看:
#ulimit -s
8192
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈