LINUX下每进程限制线程数量

参考:

http://stackoverflow.com/questions/344203/maximum-number-of-threads-per-process-in-linux

 
理论上相关限制的配置文件为:
/proc/sys/kernel/threads-max
/proc/sys/vm/max_map_count  
 
实际上最大线程数计算为:
number of threads = total virtual memory / (stack size*1024*1024) 
 
比如当前机器ulimit为:

socol@ubuntu:/etc/php5$ ulimit -a

core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 23963
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192 (= 8k)
cpu time               (seconds, -t) unlimited
max user processes              (-u) 23963
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
 
内存大小为:

socol@ubuntu:/etc/php5$ top

top - 12:51:21 up 1 day,  6:44,  2 users,  load average: 0.02, 0.12, 0.17
Tasks: 189 total,   1 running, 185 sleeping,   0 stopped,   3 zombie
Cpu(s):  3.2%us,  1.3%sy,  0.0%ni, 95.5%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    3082008k total,  1606356k used,  1475652k free,   128260k buffers
Swap:   783356k total,     3512k used,   779844k free,   723588k cached
 
最大线程数为:
3082008k/(8*1024*1024) 约等于 376个线程,与实际测试结果相符。 

你可能感兴趣的:(C/C++,OSX,ubuntu,socket,System,About)