To get the 10 processes that occupy 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
linux to get the most occupied memory resources 10 processes, you can use the following command combination:
ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head
command combination analysis (for CPU, MEN is the same):
ps aux |head -1;ps aux|grep -v PID|sort -rn -k +3|head
This command combination is actually the following two commands:
ps aux|head -1
ps aux|grep -v PID|sort -rn -k +3|head
You can use the following command to check the top 10 processes using the most memory
View the processes that consume the most CPU
ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head
or top (then press M, note the capitalization here)
View the processes with the highest memory usage
ps aux|head -1;ps aux|grep -v PID|sort -rn -k +4|head
or top (then press P, note the capitalization here)
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 to get the title (USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND).
The next grep -v PID is to remove the title obtained by the ps aux command, that is, grep does not contain the lines of the three-letter combination of PID, and then sort the results using sort.
sort -rn -k +3 The r of -rn in this command means that the results are sorted in reverse order, n is to sort by numerical size, and -k +3 is to sort the content of the third column, and then use the head command to get the default The first 10 rows of data. (where | means pipeline operation)
Supplement: Content explanation
PID: the ID of the process
USER: the owner of the process
PR: the priority level of the process, the smaller the priority is to be executed
NInice: the value
VIRT: the virtual memory
occupied by the process RES: the physical memory occupied by the process
SHR: the shared memory used by the
process S: the process status. S means sleeping, R means running, Z means dead state, N means that the priority value of the process is
negative The total occupied CPU time, that is, the accumulated value of the occupied CPU usage time. COMMAND: Process startup command name
, You can use the following command to check the K processes that use the most memory
method 1:
ps -aux | sort -k4nr | head-K
If it is 10 processes, K=10, if it is the highest three, K=3
Description: In ps -aux (a refers to all - all processes, u refers to userid - the user id that executes the process, x refers to display all programs, not distinguished by terminals)
The output format of ps -aux is as follows:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 19352 1308 ? Ss Jul29 0:00 /sbin/init root 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]
In sort -k4nr (k represents the starting position, the following number 4 is its starting position, if there is no end position, it defaults to the end; n refers to numerical sort, which is sorted according to its numerical value; r refers to reverse, This refers to the reverse comparison result, the default is from small to large when outputting, and from large to small after reverse.). In this example, you can see that %MEM is in the fourth position, and it is sorted from large to small according to the value of %MEM.
head -K (K refers to the number of rows, that is, the result of outputting the first few digits)
| is a pipe symbol, and the result of the query is imported to the following command for the next step.
Method 2: top (then press M, pay attention to capitalization)
2. You can use the following command to check the K processes that use the most CPU
method 1:
ps -aux | sort -k3nr | head-K
Method 2: top (then press P, pay attention to capitalization