How to check the number of active threads and connections on Linux?

Applications running on Linux servers often need to handle a large number of threads and connections. In order to ensure the normal operation of the system, we need to monitor the threads and connections of the system frequently to find and solve problems in time. In this article, we will detail how to view the number of active threads and connections on Linux.

Check the number of active threads

You can use the following command to see the number of active threads in the system:

$ top -H

This command will display the process list of the system, which contains information such as PID, CPU usage, memory usage, and number of threads of each process. By looking at the number of threads per process, we can tell how busy the system is with threads.

In addition, you can also use the following command to view the total number of threads of all processes in the system:

$ ps -eLf | wc -l

This command lists all processes and calculates the sum of their threads. By comparing the sum of the number of threads at different times, we can understand the thread load of the system.

Check the number of connections

You can use the following command to see the number of connections in the system:

$ netstat -an | grep :80 | wc -l

This command will display the number of all TCP connections in the system, and count the number of connections using port 80 (the default port of the HTTP protocol). By looking at the number of connections on different ports, we can understand how busy the system is on the network.

Alternatively, you can use the following command to view the number of currently open files (including network connections):

$ lsof | wc -l

This command lists all currently open files and counts their total. By comparing the number of files at different times, we can understand the network load of the system.

Summarize

It is very important to monitor threads and connections on Linux servers, which can help us discover and solve system problems in time. In this article, we described how to use commands such as top, ps, netstat, and lsof to view the number of active threads and connections. By using these commands regularly, we can understand the load on the system so that it can be optimized and tuned.

Guess you like

Origin blog.csdn.net/weixin_43025343/article/details/131865013