In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to check the occupancy rate of CPU and memory under Linux". In daily operation, I believe many people have doubts about how to view the occupancy rate of CPU and memory under Linux. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "how to check the occupancy rate of CPU and memory under Linux". Next, please follow the editor to study!
Check the occupancy of CPU and memory under Linux how to check the occupancy of CPU and memory under Linux. Then I will introduce several methods through SALI-IMX6Q as an example: method 1: how to check the occupancy of memory under Linux
We can use a combination of the following commands to do this. In this method, we use a combination of free and awk commands to obtain memory usage.
To get the memory usage that does not contain a percentage symbol:
# free-t | awk'NR = = 2 {print "Current Memory Utilization is:" $3 Universe 2100}'
Or
# free-t | awk 'FNR = = 2 {print "Current Memory Utilization is:" $3 Universe 2100}'
Current Memory Utilization is: 18.0433
To get the memory usage that contains the percentage symbol and retains two decimal places:
# free-t | awk'NR = 2 {printf ("Current Memory Utilization is:% .2f%"), $3pm
Or
# free-t | awk 'FNR = 2 {printf ("Current Memory Utilization is:% .2f%"), $3pm
Current Memory Utilization is: 18.06%
Typing the free command will better explain:
Root@imx6qdlsolo:~# free
Total used free shared buff/cache available
Mem: 1024780 185096 783012 1036 56672 769256
Swap: 0 0 0
Details are as follows:
Free: is a standard command for viewing memory usage under Linux.
Awk: a powerful command specifically for text data processing.
FNR = = 2: this command gives the number of lines for each input file. It is basically used to pick out a given row (for this case, it selects the line with line number 2)
NR = = 2: this command gives the total number of rows processed. It is basically used to filter the given row (for this case, it selects the line with line number 2)
$3Universe 100: this command divides column 3 by column 2 and multiplies the result by 100.
Printf: this command is used to format and print data.
% .2f%: by default, it retains a floating-point number of 6 places after printing the decimal point. Use the following format to constrain decimal places.
Method 2: how to check the memory occupancy under Linux
We can use a combination of the following commands to do this. In this approach, we use a combination of free, grep, and awk commands to obtain memory usage.
To get the memory usage that does not contain a percentage symbol:
# free-t | grep Mem | awk'{print "Current Memory Utilization is:" $3max 2mm 100}'
Current Memory Utilization is: 18.071
To get the memory usage that contains the percentage symbol and retains two decimal places:
# free-t | grep Mem | awk'{printf ("Current Memory Utilization is:% .2f%"), $3pm
Current Memory Utilization is: 18.07%
Method 3: how to check the occupancy of CPU under Linux we can use a combination of the following commands to achieve this. In this approach, we use a combination of top, print, and awk commands to obtain CPU occupancy.
If you are showing multiple CPU in the output, you need to use the following method.
# top-b-N1 | grep ^% Cpu
% Cpu (s): 0.1 us, 0.4 sy, 0.0 ni, 99.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
To get the CPU occupancy that does not contain a percentage symbol:
# top-b-N1 | grep ^% Cpu | awk'{cpu+=$9} END {print "Current CPU Utilization is:" 100-cpu/NR}'
Current CPU Utilization is: 100
To get the CPU occupancy that contains the percentage sign and retains two decimal places:
# top-b-N1 | grep ^% Cpu | awk'{cpu+=$9} END {printf ("Current CPU Utilization is:% .2f%"), 100-cpu/NR}'
Current CPU Utilization is: 100.005%
Method 4: how to check the occupancy rate of CPU under Linux
We can do this using a combination of the following commands. In this approach, we use a combination of top, print/printf, and awk commands to obtain CPU occupancy.
If all the CPU cases are shown together in a single output, then you need to use the following method.
# top-b-N1 | grep ^% Cpu
% Cpu (s): 0.1 us, 0.4 sy, 0.0 ni, 99.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
To get the CPU occupancy that does not contain a percentage symbol:
# top-b-N1 | grep ^% Cpu | awk'{print "Current CPU Utilization is:" 100Mexico 8}'
Current CPU Utilization is: 0.5
To get the CPU occupancy that contains the percentage sign and retains two decimal places:
# top-b-N1 | grep ^% Cpu | awk'{printf ("Current CPU Utilization is:% .2f%"), 100 Mustang 8}'
Current CPU Utilization is: 0.50%
Here are some details:
Top: a very good command for viewing processes running on the current Linux system.
-b: option allows the top command to switch to batch mode. It is very useful when you run the top command from the local system to the remote system.
-N1: iterations.
^% Cpu: filter lines that start with% CPU.
Awk: a powerful command specifically used for text data processing.
Cpu+=$9: for each row, add column 9 to the variable cpu.
Printf: this command is used to format and print data.
% .2f%: by default, it retains a floating point of 6 places after printing the decimal point. Use the following format to limit the number of decimal places.
100-cpu/NR: finally prints out the average occupancy of CPU, which is subtracted by 100 and divided by the number of lines.
So you can check it out. Like to pay more attention to it!
At this point, the study on "how to check the occupancy of CPU and memory under Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.