linux - [Solved-5 Solutions] Maximum number of threads per process in Linux - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
What is the maximum number of threads that can be created by a process under Linux?
Linux - Solution 1:
The default is the number of memory pages/4. You can increase this like:
There is also a limit on the number of processes (and hence threads) that a single user may create.
Linux - Solution 2:
Linux doesn't have a separate threads per process limit.
Linux implements max number of threads per process indirectly
Thus, the number of threads per process can be increased by increasing total virtual memory or by decreasing stack size.
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:
Linux - Solution 3:
Checking the current number of threads used
The following command will output the number of processes for the myfasuser (example) user. Note: Threads are counted as processes in linux
If the number is less than 200 try without the -H flag as the Thread toggle may have already been set in top
The highest of these 2 outputs indicates the number of myfasuser processes A base line Cafex installation will typically use around 700 threads in a quiescent state and this figure will rise over time with traffic and the full product set deployed.
Linux - Solution 4:
To retrieve it:
To set it:
Linux - Solution 5:
Linux doesn't use the virtual memory to calculate the maximum of thread, but the physical ram installed on the system
kernel/fork.c
- Thread max is different between every system, because the ram installed can be from different sizes, I know Linux doesn't need to increase the virtual memory, because on 32 bit we got 3 GB for user space and 1 GB for the kernel, on 64 bit we got 128 TB of virtual memory, that happen on Solaris, if you want increase the virtual memory you need to add swap space.