Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Linux check the occupancy status of CPU

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how Linux views CPU occupancy status". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn "how Linux views CPU occupancy status" together.

TOP View information about only one or some processes

top using CPU or MEM sort, or do not see the process we want to know about the relevant information;

At this time, you can specify a TOP information display for a certain or some processes;

1. View information about a process

Example: Information on mysqld

(1)Get pid of mysqld process [root@6 ~]# pidof mysqld21538(2)top Specify view PID[root@6 ~]# top -p 21538

2. View information about certain processes pidof

Example: mysqld/httpd info (1) Get mysqld/httpd process pid[root@6 ~]# pidof mysqld21538[root@6 ~]# pidof httpd31117 31116 31115 31114(2)top Specify view PID[root@6 ~]# top -p 21538,31117,31116,31115,31114

To get the 10 processes that consume the most CPU resources under linux, you can use the following command combination:

ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head

To get the 10 processes that occupy the most memory resources under linux, you can use the following command combination:

ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head

The command combination is actually the following two commands:

ps aux|head -1ps aux|grep -v PID|sort -rn -k +3|head

You can use one command to find the 10 processes that use the most memory

View the processes with the highest CPU usage

ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head

or top (then press M, note that this is capitalized)

View the most memory-intensive processes

ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head

or top (and then press P, note that this is capitalized)

The command combination is actually the following two commands:

ps aux|head -1

ps aux|grep -v PID|sort -rn -k +3|head

The first sentence is mainly for obtaining the title (USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND).

The next grep -v PID is to remove the header obtained by ps aux command, that is, grep does not contain the three letter combinations of PID, and then sort the results.

sort -rn -k +3 The r of-rn in this command means that the results are sorted in reverse order, n is sorted by numerical size, and-k +3 is sorted for the contents of column 3, and then use the head command to get the default first 10 rows of data. (Among them| indicates pipeline operation)

Supplement: Content explanation

PID: Process ID

USER: process owner

PR: priority of the process, the smaller the priority to be executed

Nice Ince: Value

VIRT: Virtual memory occupied by processes

RES: Physical memory occupied by the process

SHR: Shared memory used by processes

S: Status of the process. S means dormant, R means running, Z means dead, N means negative priority value for the process

%CPU: CPU usage by processes

%MEM: Percentage of physical memory and total memory used by the process

TIME+: The total CPU time occupied by the process after it starts, that is, the cumulative value of the CPU usage time occupied.

COMMAND: Process start command name

You can use the following command to find the K processes that use the most memory

Method 1:

ps -aux | sort -k4nr | head -K

K=10 if there are 10 processes, K=3 if there are the highest three

Description: ps -aux (a refers to all--all processes, u refers to userid--the user id who executes the process, x refers to all programs displayed, not distinguished by terminal)

The output format of ps -aux is as follows:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.0 19352 1308 ? Ss Jul29 0:00 /sbin/initroot 2 0.0 0.0 0 0 ? S Jul29 0:00 [kthreadd]root 3 0.0 0.0 0 0 ? S Jul29 0:11 [migration/0]

sort -k4nr (k represents the position from which it starts, and the number 4 after it is the starting position. If there is no ending position, it defaults to the last;n refers to numerical sort, sorted according to its numerical value;r refers to reverse, which refers to the reverse comparison result. The default output is from small to large, and from large to small after reverse.). In this example, you can see that %MEM is in the fourth position, sorted from large to small according to the value of % MEM.

head -K (K refers to the number of rows, i.e. the first few bits of the output)

|For pipe symbol, direct the query result to the following command for the next operation.

Second, you can use the following command to check the K processes that use the most CPU

Method 1:

ps -aux | sort -k3nr |head -K Thank you for reading, the above is "Linux how to view the CPU occupation status" of the content, after the study of this article, I believe that everyone on Linux how to view the CPU occupation status of this problem has a deeper understanding, the specific use of the situation also needs everyone to practice verification. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report