What is the maximum number of threads per process in Linux?

LinuxOperating SystemOpen Source

There are multiple ways with which we can check the maximum number of threads that Linux has allocated to a particular process.

Approach 1

cat /proc/sys/kernel/threads-max

Output

61741

We can also increase the default value set by linux with the help of the command shown below −

echo 123456789 > /proc/sys/kernel/threads-max

where 123456789 = Number of threads

Approach 2

It is also known that Linux doesn’t have a separate threads per limit and it basically implemented the maximum number of threads per process indirectly.

Command

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

So the threads per process can be increased by decreasing the stack size or increasing the virtual memory.

We can also increase the virtual memory on our machine with the help of the command shown below −

ulimit -s newvalue

In the above command, you should replace the new value with the value that you want to put as the limit.

The stack size can be increased with the help of the command shown below −

ulimit -v newvalue

In the above command you should replace the new value with the value that you want to put as the limit.

raja
Published on 31-Jul-2021 12:17:19
Advertisements