實(shí)際的系統(tǒng)進(jìn)程數(shù)上限收到3個(gè)配置項(xiàng)的影響:
1、threads-max (/proc/sys/kernel/threads_max)
這個(gè)值表示物理內(nèi)存決定的系統(tǒng)進(jìn)程數(shù)上限,fork_init中有:
max_threads = mempages / (THREAD_SIZE/PAGE_SIZE) / 8
2、pid_max (/proc/sys/kernel/pid_max)
這個(gè)值表示進(jìn)程ID的上限。為了兼容舊版,默認(rèn)為32768(即兩個(gè)字節(jié))。
<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">echo <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4194303</span> > <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/proc/sys</span><span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/kernel/pid</span>_max</code>
3、RLIMIT_NPROC (ulimit -u 或者 getrlimit)
這個(gè)值表示單個(gè)用戶允許的最大進(jìn)程數(shù)上限。系統(tǒng)默認(rèn)為threads-max的一半:
init_task.rlim[RLIMIT_NPROC].rlim_cur = max_threads/2;
init_task.rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
實(shí)驗(yàn):
某環(huán)境上:
threads-max = 139264;
pid_max = 32768
RLIMIT_NPROC = 69632
1、此時(shí),使用根用戶不斷創(chuàng)建進(jìn)程,最終創(chuàng)建了約32378,考慮到原有的進(jìn)程數(shù),比較接近pid_max這個(gè)值;
2、改pid_max為18000時(shí),最終創(chuàng)建了17612個(gè)進(jìn)程;
3、修改pid_max為80000,換成普通用戶,最終創(chuàng)建了67913個(gè)進(jìn)程
總結(jié)
以上所述是小編給大家介紹的linux 進(jìn)程數(shù)最大值修改方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!