Maximum number of threads per process in Linux?

前端 未结 16 2794
轮回少年
轮回少年 2020-11-22 02:16

What is the maximum number of threads that can be created by a process under Linux?

How (if possible) can this value be modified?

16条回答
  •  清酒与你
    2020-11-22 02:56

    check the stack size per thread with ulimit, in my case Redhat Linux 2.6:

        ulimit -a
    ...
        stack size              (kbytes, -s) 10240
    

    Each of your threads will get this amount of memory (10MB) assigned for it's stack. With a 32bit program and a maximum address space of 4GB, that is a maximum of only 4096MB / 10MB = 409 threads !!! Minus program code, minus heap-space will probably lead to an observed max. of 300 threads.

    You should be able to raise this by compiling and running on 64bit or setting ulimit -s 8192 or even ulimit -s 4096. But if this is advisable is another discussion...

提交回复
热议问题