Maximum number of threads per process in Linux?

前端 未结 16 2830
轮回少年
轮回少年 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:49

    This is WRONG to say that LINUX doesn't have a separate threads per process limit.

    Linux implements max number of threads per process indirectly!!

    number of threads = total virtual memory / (stack size*1024*1024)
    

    Thus, the number of threads per process can be increased by increasing total virtual memory or by decreasing stack size. But, decreasing stack size too much can lead to code failure due to stack overflow while max virtual memory is equals to the swap memory.

    Check you machine:

    Total Virtual Memory: ulimit -v (default is unlimited, thus you need to increase swap memory to increase this)

    Total Stack Size: ulimit -s (default is 8Mb)

    Command to increase these values:

    ulimit -s newvalue
    
    ulimit -v newvalue
    

    *Replace new value with the value you want to put as limit.

    References:

    http://dustycodes.wordpress.com/2012/02/09/increasing-number-of-threads-per-process/

提交回复
热议问题