Linux View CPU Memory usage

Source: Internet
Author: User
Tags cpu usage

During system maintenance, it may be necessary to review the CPU usage at any time, and to analyze the system condition according to the corresponding information. In CentOS, you can view CPU usage by using the top command. After running the top command, the CPU usage status is displayed in full-screen mode, and will be in the dialog-using top-based commands, you can control how the display is displayed, and so on. The command to exit Top is Q (the Q key is struck once in the top run).

The top command is a common performance analysis tool under Linux that shows the resource usage of individual processes in the system in real time, similar to the Task Manager for Windows

You can view the contents of the%mem directly after you use the top command. You can choose to view by process or view by user, and you can use the following command if you want to see the process memory usage of the ping User:
$ top-u Ping

Content Explanation:

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

Operation Example:

Enter "Top" on the command line

You can start the top

  top Full Screen Dialog mode can be divided into 3 parts: System Information Bar, command input field, process list bar .

The first part-the top System Information Bar:

First line (top):

"14:54:10" is the current time of the system;

"Days" for the system after the start of the operation of the current time;

"Users" for the current user logged on to the system, or more specifically the number of users logged on to the terminal-the same user at the same time to multiple terminals of the system will be treated as multiple users connected to the system, where the number of users will also be represented as the number of terminals;

"Load average" is the average of the current system load, the following three values are 1 minutes ago, 5 minutes ago, 15 minutes ago The average process, the general can be thought that this value exceeds the number of CPUs, the CPU will be more strenuous load the current system contains the process;

Second line (Tasks):

"1766 Total" is the current number of system processes;

"7 Running" is the number of processes currently in operation;

"1754 Sleeping" is the number of processes currently in the waiting state;

"5 stoped" for the number of system processes stopped;

"0 Zombie" for the number of processes restored;

Third line (Cpus):

CPU (s): 13.6% US user space consumes CPU percentage
1.0% SY core space CPU percent occupied
0.0% CPU Percentage of processes that have changed priority within NI user process space
85.3% ID Idle CPU percent
0.1% wa wait for the input output CPU time percentage
0.0% hi
0.0% Si 0.0% St

Line Four (MEM):

Represents the total amount of physical memory, the total amount of physical memory currently used, the total amount of free memory, and the amount of memory used in buffering;

Line Five (Swap):

Represents the category with the fourth line (MEM), but here reflects the use of the Swap partition (swap). Typically, swap partitions (swap) are frequently used, and will be seen as a result of insufficient physical memory.

The second part--the inner command prompt bar of the middle part:

In the top run, you can control how processes are displayed through the internal commands of top. The internal command is the following table:

S-Change the screen update frequency

L-Turn off or turn on the representation of the first line top information in the first section

T-turn off or turn on the second line of the first section Cpus information representation of the Tasks and the third row

M-Turn off or turn on the first part of the four-line Mem and fifth line Swap information representation

N-the list of processes in the order of the PID size (the third part is described later)

P-List of processes in the Order of CPU Utilization (third part)

M-Arrange the list of processes in the Order of Memory occupancy (Part III)

H-Show help

N-Set the number of processes displayed in the process list

Q-Exit Top

Part Three-the bottom part of the Process list bar:

A list of processes that are separated by PID will be updated periodically based on the Set screen update time. The top internal command lets you control how it is displayed here

Pmap

Depending on the process, you can view the memory used by the process-related information (the process number can be viewed by PS) as follows:
$ pmap-d 5647

Ps

As shown in the following example:
$ ps-e-O ' pid,comm,args,pcpu,rsz,vsz,stime,user,uid ' where Rsz is the actual memory
$ ps-e-o ' pid,comm,args,pcpu,rsz,vsz,stime,user,uid ' |  grep Oracle | Sort-nrk

Where Rsz is the actual memory, the above example is implemented by memory sort, from large to small

View memory under Linux We generally use the free command:

Here is an explanation of these values:
Total: The amount of physical memory.
Used: How large is used.
Free: How much is available.
Shared: The total amount of memory shared by multiple processes.
Buffers/cached: The size of the disk cache.
Third row (-/+ buffers/cached): Used: How big is used. Free: How much is available.
There is not much to explain in line four.
Difference: The used/free of the second line (MEM) differs from the third row (-/+ Buffers/cache) used/free. The difference between the two is that the first line is from the OS point of view, because for the os,buffers/cached all belong to be used, so his available memory is 495810672, the used memory is 298187016, which includes, the kernel (OS) uses + Application (X, ORACLE,ETC) uses the +buffers+cached.
The third line refers to the application from the point of view, buffers/cached is equal to the availability of the application, because buffer/cached is to improve the performance of the file read, when the application needs to use memory, buffer/cached will be quickly recycled.
So from the application's point of view, available memory = System Free memory+buffers+cached.

Next, explain when the memory will be exchanged and in what way. When the available memory is less than the rated value, a meeting is exchanged.
How to see the rating:
Cat/proc/meminfo

Results viewed with free-m:

To view the size of the/proc/kcore file (memory image):

Note:

Memory-intensive measurements

To measure how much memory a process consumes, Linux provides a convenient way for us to provide all the information we have in the/proc directory, and in fact the top tools are also available here to obtain the appropriate information.

Memory usage information for/proc/meminfo machines

The/proc/pid/maps PID is the process number that displays the virtual address occupied by the current process.

Memory occupied by the/PROC/PID/STATM process

Output interpretation

CPU and CPU0 ... The meaning of each parameter of each row (in the first example) is:

Parameter Interpretation/proc//status

Size (pages) task virtual address space VMSIZE/4

Resident (pages) the size of the physical memory that the application is using VMRSS/4

Shared (pages) pages 0

The size of the executable virtual memory owned by the TRS (pages) program VMEXE/4

The size of the library in which Lrs (pages) is imaged into the virtual memory space of the task VMLIB/4

Drs (pages) program data segment and user-state stack size (vmdata+ VMSTK) 4

DT (pages) 04

View Machine available memory

/proc/28248/>free

Total used free shared buffers Cached

mem:1023788 926400 97388 0 134668 503688

-/+ buffers/cache:288044 735744

swap:1959920 89608 1870312

When we look at the idle memory of the machine with the free command, we find that the value of the. This is mainly because, in Linux there is such a thought, the memory is not white, so it as far as possible cache and buffer some data to facilitate the next use. But in fact, the memory is also available for immediate use.

So free memory =free+buffers+cached=total-used

Linux View CPU Memory usage

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.