What is the maximum number of threads that can be created by a process under Linux?
How (if possible) can this value be modified?
What is the maximum number of threads that can be created by a process under Linux?
How (if possible) can this value be modified?
Yes, to increase the threads number you need to increase the virtual memory or decrease the stack size. In Raspberry Pi I didn’t find a way to increase the virtual memory, if a decrease the stack size from default 8MB to 1MB It is possibly get more than 1000 threads per process but decrease the stack size with the “ulimit -s” command make this for all threads. So, my solution was use “pthread_t” instance “thread class” because the pthread_t let me set the stack size per each thread. Finally, I am available to archive more than 1000 threads per process in Raspberry Pi each one with 1MB of stack.
Linux doesn't have a separate threads per process limit, just a limit on the total number of processes on the system (threads are essentially just processes with a shared address space on Linux) which you can view like this:
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, see
ulimit/getrlimit
for details regarding these limits.@dragosrsupercool
Linux doesn't use the virtual memory to calculate the maximum of thread, but the physical ram installed on the system
http://kavassalis.com/2011/03/linux-and-the-maximum-number-of-processes-threads/
kernel/fork.c
So 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.
We can see the maximum number of threads defined in the following file in linux
cat /proc/sys/kernel/threads-max
(OR)
sysctl -a | grep threads-max