Get the App
SLTechnology News&Howtos  ›  Development  › 

How to limit the total number of threads in a Linux system

Shulou Source: shulou.com Published: 2022-06-01 20:24:10 10月25日 Update

Xiaobian to share with you how to limit the total number of threads in the Linux system, I believe most people still do not know how to share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

1. Summarize the system limitations: /proc/sys/kernel/pid_max #Check the maximum number of threads supported by the system, which is generally large, equivalent to the theoretical value.

/proc/sys/kernel/threads-max

max_user_process #The system limits the maximum number of processes or threads a user can run, using the command:ulimit -u

Note: To modify the max_user_process value, you only need to modify/etc/security/limits.conf, but this parameter needs to modify/etc/security/limits.d/90-nproc.conf

Appendix 1: Centos 6.* You can modify/etc/security/limits.d/90-nproc.conf by modifying/etc/security/limits.conf and adding * soft nproc 65535 * hard nproc 65535 at the end.

To view the default thread stack size in bytes, use the command:ulimit -s

/proc/sys/vm/max_map_count #Hardware Memory Size

Java virtual machine itself limit: -Xms #initial java heap size -Xmx #maximum java heap size -Xss #the stack size for each thread

3. Query the number of threads or processes of a current program # pstree -p ps -e| grep java | awk '{print $1}' | wc -l

Command substitution is used above. For command substitution, that is, the command enclosed in "will take precedence and then use its output as an argument to other commands or # pstree -p process number."| wc -l

# top -H process number| wc -l

It's called pipe. About pipe: pipe symbol."|"The output of the command on the left serves as input to the command on the right.

4. Query the number of threads or processes currently used by the entire system pstree -p| wc -l

The above is "How to limit the total number of threads in Linux system" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Commands threads systems restrictions processes pipes articles content parameters size appendices queries output large maximum not much memory units right most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft vpn Huawei Shulou Information Linux