Top and FREE commands in Linux (6/15)

Source: Internet
Author: User
Tags cpu usage

Top: The command provides real-time status monitoring of the system's processor. It displays a list of the most "sensitive" tasks for the CPU in the system.

This command can be used on a per-CPU basis. Memory usage and execution time sorting tasks;

And many of the features of the command can be set through interactive commands or in personal customization files.

top-01:06:48 up 1:22, 1 user, load average:0.06, 0.60, 0.48

tasks:29 Total, 1 running, sleeping, 0 stopped, 0 zombie

Cpu (s): 0.3% us, 1.0% sy, 0.0% ni, 98.7% ID, 0.0% wa, 0.0% Hi, 0.0% si

mem:191272k Total, 173656k used, 17616k free, 22052k buffers

swap:192772k Total, 0k used, 192772k free, 123988k cached

PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND

1379 Root 0 7976 2456 1980 S 0.7 1.3 0:11.03 sshd

The top command is a common performance analysis tool under Linux that shows the resource usage of each process in the system in real time. The command to exit Top is Q (the Q key is struck once in the top run)

    1. 0> Top-u PSO

The first five elements of the statistical information area are the statistical information of the whole system. The first line is the task queue information, with the execution result of the uptime command. The contents are as follows:

01:06:48 Current Time

Up 1:22 system power on to the current operating hours, units: minutes

1 user Current number of users logged on

Load average:0.06, 0.60, 0.48 system load, which is the average length of the task queue.

The three values were 1 minutes, 5 minutes, and 15 minutes ago to the present average.

The second to third behavior process and CPU information. When there are multiple CPUs, the content may be more than two lines. The contents are as follows:

    1. tasks:126 Total, 1 running, sleeping, 0 stopped, 0 zombie

Tasks "127 Total" process totals
Number of processes running "1 running"
Number of processes for "sleeping" sleep
Number of processes "0 stoped" stopped
Number of "0 zombie" zombie processes


Cpu (s): 1.8%us, 0.5%sy, 0.0%ni, 97.1%id, 0.0%wa, 0.0%hi, 0.5%si, 0.0%st

Cpus indicates the current utilization of the CPU respectively;

1.8%us User space consumption CPU percentage
0.5%sy CPU percent of kernel space consumed
0.0%ni CPU Percentage of processes that have changed priority within the user process space
97.1%id Idle CPU Percentage
0.0%wa percentage of CPU time waiting for input and output
0.0%hi

0.5%si

0.0%st

mem:8057552k Total, 7905920k used, 151632k free, 397224k buffers

Mem represents the total amount of memory, current usage, amount of idle memory, and amount of RAM used in buffering;

Total physical memory of 8057552k
Total physical memory used by 7911076k used
146476k free Memory Total
The amount of memory that 395284k buffers uses as the kernel cache

    1. swap:8191996k Total, 82588k used, 8109408k free, 2308104k cached

Swap indicates a category with mem, but this reflects the usage of the Swap partition (swap). Typically, swap partitions (swap) are frequently used, and will be seen as a result of insufficient physical memory.

Total Swap Area 8191996k
Total swap area used by 83008k used
8108988k Free Swap Area total
2315284k cached Buffers The total number of swap areas.
The in-memory content is swapped out to the swap area and then swapped in to memory, but the used swap area has not been overwritten.
This value is the size of the swap area where the content already exists in memory. When the corresponding memory is swapped out again, it is no longer necessary to write to the swap area.

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 commands are as follows:

Space > Refresh Now
s Change the screen update frequency
L Close/Turn on the representation of the top information in the first section
T close/Open the first part of the tasks and Cpus information representation
M close/Open the first part of the MEM and Swap information representation
H Display Help
n Sets the number of processes that are displayed in the process list
C Toggle Display command name and full command line
Q Exit Top
N the list of processes in the order of the PID size
P List of processes in the order of CPU utilization
M arrange the list of processes in the order of memory utilization size
T Sort by time, cumulative time
W writes the current settings to the ~/.TOPRC file. This is the recommended way to write top configuration files.

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


%CPU:
%MEM:
Time+:
Command: Process start name

The details of each process are shown below the process information area statistics area. The meanings of the columns are as follows:
Column name meaning
PID Process ID
PPID Parent Process ID
Ruser Real User Name
User ID of the UID process owner
Username of user Process Owner
Group Process Owner's name
The terminal name of the TTY startup process. Processes that are not started from the terminal are displayed as?
PR-Priority
NI nice value. Negative values indicate high priority, positive values indicate low priority
P last used CPU, only meaningful in multi-CPU environment
%CPU CPU time consumption as a percentage of the last update to the present, process consuming CPU utilization

Percent of physical memory used by the%MEM process, the amount of physical memory used by the process and the percentage of total memory

The total CPU time, in seconds, used by the duration process
The total CPU time used by the time+ process, in 1/100 seconds after the process started, which is the cumulative value of CPU usage time.

The total amount of virtual memory used by the VIRT process, in kilobytes. Virt=swap+res
The swap process uses the amount of virtual memory that is swapped out, in kilobytes.
The size, in kilobytes, of the physical memory used by the RES process and not swapped out. Res=code+data
The amount of physical memory the code executable consumes, in kilobytes per kb
The amount of physical memory that is used outside the data executable code (segment + stack), in kilobytes
The amount of shared memory used by the SHR process, in kilobytes
Nflt Number of page faults
NDRT the number of pages that were modified the last time it was written to.

S process state.
D = Non-interruptible sleep state
R = Run
S = Sleep
T = trace/Stop
Z = Zombie Process
Command name/command line
Wchan If the process is sleeping, the system function name in sleep is displayed
Flags task flag, reference sched.h

By default, only the more important PID, USER, PR, NI, VIRT, RES, SHR, S,%cpu,%MEM, time+, and COMMAND columns are displayed.

F key to select what to display: Press the F key to enter the view where you want to display the field, display a list of columns,
Press A-Z to show or hide the corresponding column, fields with * are displayed, no * number is not displayed, and finally press ENTER to confirm.

Press the O key to change the order in which the columns are displayed.

A-Z in the lower case moves the corresponding column to the right, while the uppercase A-Z moves the corresponding column to the left. Finally, press ENTER to confirm.


Press the uppercase F or O key, and then press A-Z to sort the process by the appropriate column.
The uppercase R key can reverse the current sort.

Press b the key to turn on or off the highlight effect of the running process

    • Press x the key to turn on or off the highlight effect of the row sequence

    • shift + >Or shift + < You can change the row sequence to the right or left

The top command is a powerful tool for monitoring systems, and its disadvantage is that it consumes a lot of system resources.

The top command monitors the specified user, and the default is to monitor all users ' processes. If you want to view the situation of the specified user, press the "U" key in the terminal and enter the user name, the system will switch to the user's process run interface.

Pmap

The memory used by process-related information can be viewed according to the progress number

[[email protected] a22-15-10.120.64.173]:/app/tomcat-callcenter2.0

      1. 0> pmap-d 17854

The free command is used to display memory usage

B. Format

Free [-b-k-M] [-O] [-s delay] [-t] [-v]

C. Main parameters

-b-k-M: Displays memory usage in bytes (KB, MB), respectively.

-S delay: Displays the number of seconds per second to show memory usage.

-T: Displays the memory sum column.

-O: Do not display buffer throttling columns.

After using this command, the terminal will continually report memory usage (in bytes), updated every 5 seconds

#free-b-S5

Total used free shared buffers Cached

mem:3266180 3250004 16176 0 110652 2668236

-/+ buffers/cache:471116 2795064

swap:2048276 80160 1968116

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.

The difference between the used/free of the second line (MEM) and the third row (-/+ Buffers/cache) Used/free is the angle of use,

Mem is from the OS point of view, for os,buffers/cached are all belong to be used, usable memory is 178072KB, memory used is 7879480KB, including, kernel (OS) using +application (X, ORACLE,ETC) +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. As in the example above: 2859864=178072+395020+2286772

Third line (-/+ buffers/cached):

Used: How large 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 in terms of use,

The first line is from the OS point of view, because for the os,buffers/cached are all belong to be used, so his available memory is 16176KB, used memory is 3250004KB, which includes, the kernel (OS) uses +application (X, Oracle, etc) using 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.

As in the example above: 2795064=16176+110652+2668236

Next, explain when the memory will be exchanged, and by what side. When the available memory is less than the rated value, a meeting is exchanged.

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

Buffer cache, also known as Bcache, wherein the text name is buffer cache buffer memory, short buffer high slow. In addition, the buffer cache in accordance with its working principle, also known as Block high slow.

When Linux reads and writes files, it is used to cache disk blocks on a physical disk, which speeds up access to data on disk.

The contents of the buffer cache correspond to a block on the disk (block), usually 1 K, and are contiguous.

Under Linux, for more efficient use of physical memory, the operating system automatically uses all free memory as buffer cache. The operating system will automatically reduce the cache size when the program needs more memory

The difference between buffer and cache

A buffer is something that have yet to being "written" to disk. A cache is something that have been "read" from the disk and stored for later use.

For a more detailed explanation reference: difference between Buffer and Cache

For shared memory, which is primarily used to share data between different processes in a UNIX environment, is a method of interprocess communication, and the general application does not request the use of shared memory, nor does the author verify the effect of shared memory on the above equation. If you are interested, please refer to: What is Shared Memory?

The difference between cache and buffer:

Cache: Caching is a small but high-speed memory that sits between the CPU and the main memory. Because the CPU speed is much higher than the main memory, the CPU accesses the data directly from the memory to wait for a certain period of time, the cache holds the CPU just used or recycled part of the data, when the CPU re-use the part of the data can be directly called from the cache, which reduces the CPU waiting time, Improve the efficiency of the system. The cache is also divided into one-level cache (L1 cache) and level two cache (L2 cache), L1 cache is integrated within the CPU, L2 cache is usually soldered to the motherboard, and is now integrated into the CPU, with a common capacity of 256KB or 512KB L2 Cache.

Buffer: An area where data is transferred between devices that are not synchronized or that have different priority levels. Through buffers, you can reduce the number of waits between processes, so that when you read data from a slow device, the operating process of a fast device is uninterrupted.

Buffer and cache in free: (They are all memory-intensive):

Buffer: Memory as buffer cache, which is the read and write buffer of the block device

Cache: As the page cache memory, the file system cache

If the cache has a large value, it indicates that the cache has a high number of files. If frequently accessed files can be cache, then the disk read IO must be very small.

Top and FREE commands in Linux (6/15)

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.