How to see which processes consume the most CPU and memory resources under Linux

Source: Internet
Author: User
Tags cpu usage

Under Linux, get the 10 processes that consume the most CPU resources, using a combination of the following commands:

PS Aux|head-1;ps aux|grep-v pid|sort-rn-k +3|head



Under Linux, get the 10 most memory-intensive processes, which can be combined using the following command:

PS Aux|head-1;ps aux|grep-v pid|sort-rn-k +4|head






Command combination parsing (for CPU, men also):

PS Aux|head-1;ps aux|grep-v pid|sort-rn-k +3|head



This combination of commands is actually the following two lines of command:

PS Aux|head-1

PS Aux|grep-v pid|sort-rn-k +3|head

You can use the command to check the 10 processes with the most memory

View the process that consumes the highest CPU

PS Aux|head-1;ps aux|grep-v pid|sort-rn-k +3|head

or top (then press m, note that this is uppercase)

View the most memory-intensive processes

PS Aux|head-1;ps aux|grep-v pid|sort-rn-k +4|head

or top (then press p, note that this is uppercase)

This combination of commands is actually the following two lines of command:

PS Aux|head-1
PS Aux|grep-v pid|sort-rn-k +3|head

The first sentence is primarily 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 of the PS aux command, that is, grep does not contain the three-letter combination of the PID line, and then the result is sorted using sort.
Sort-rn-k +3 the-rn R in this command is ordered in reverse order, n is sorted by numeric size, and-K +3 is sorted for the contents of column 3rd, and the first 10 rows of data are obtained by using the Head command. (where | represents a pipeline operation)

Supplemental: Content Interpretation

PID: ID of the process
USER: Process Owner
PR: The priority level of the process, the smaller the higher the priority is executed
Ninice: Value
VIRT: Virtual memory consumed by the process
RES: The physical memory occupied by the process
SHR: Shared memory used by the process
S: The state of the process. s for hibernation, R for running, Z for Zombie, n for the process priority value is negative
%CPU: Process Consuming CPU utilization
%MEM: The percentage of physical memory and total memory used by the process
Time+: The total CPU time that is consumed after the process is started, which is the cumulative value of the CPU usage time.
Command: Process start name

, you can use the following command to check the K processes using the most memory

Method 1:

Ps-aux | Sort-k4nr | Head-k

If it is 10 processes, k=10, if it is the highest of three, k=3

Description:in Ps-aux (a refers to all the processes of all--, u refers to the userid--executing the process, the user id,x means to display all programs, not to differentiate by terminal)

The output format of the 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 starting from the first position, the following number 4 is the beginning of the position, the end position if not, then the default to the last; n refers to the numberic sort, according to its numerical order; R refers to the reverse, here refers to the reverse comparison results, the output by default from small to large, Reverse backwards from large to small. )。 In this example, you can see%mem in the 4th position, based on the value of%mem, from the large to the small sort.

Head-k (K refers to the number of rows, which is the result of the first few outputs)

| For the pipe symbol, the result of the query is directed to the following command for next steps.

Method 2:top (then press m, note upper case)

Second, you can use the following command to check the use of the most CPU K process

Method 1:

Ps-aux | Sort-k3nr | Head-k

Method 2:top (then press p, note uppercase

How to see which processes consume the most CPU and memory resources under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.