linux 进程的最大线程个数
1. 可以通过下面的方法查到:[plain] view plaincopyprint?cat /proc/sys/kernel/threads-max 15882 另外,一个进程实际的线程个数,可以从 /proc/{PID}/status里得出:[plain] view plaincopyprint?/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 里算出来的:[cpp] view plaincopyprint?/* * 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); [cpp] view plaincopyprint?#define THREAD_SIZE 8192 mempages 是物理内存的大小(以页面为单位)。可以用如下方法查到:[cpp] view plaincopyprint?cat /proc/zoneinfo | grep spanned | awk '{totalpages=totalpages+$2 } END {print totalpages}' THREAD_SIZE为线程的栈大小。可以用 ulimit 查看:[cpp] view plaincopyprint?#ulimit -s 8192