View Linux system Resource Usage commands (top, free, uptime)

Source: Internet
Author: User
Tags cpu usage

This article describes the three commands that are used to view system resources in Linux: Top, free, uptime, learn their usage through examples, and refer to the friends who need them.

One, Top command

2. Use
The top command is used to display the program process in progress, and the permissions are all users.

2. Format
Top [-] [D delay] [Q] [C] [s] [s] [i] [n]

3. Main parameters
D: Specifies the interval of the update, in seconds.
Q: There are no delayed updates. If the user has a superuser, the top command will be executed with the highest precedence.
C: Displays the full path and name of the process.
S: Cumulative mode, which accumulates the CPU time of a child stroke that has completed or disappeared.
S: Safe mode.
I: Do not display any idle (idle) or useless (Zombie) travel.
N: Displays the number of updates and exits top when finished.

Statistical information about the current system as a whole

The top five elements of the first command display are statistical information about the system as a whole.

The first line is the task queue information, with the execution result of the uptime command. eg.

top-15:09:51 up + days, 3:38, 4 users, Load average:1.09, 3.39, 4.76

15:09:51 Current time
up + days, 3:38 system run time, format last:
4 users currently logged on
Load average:1.09, 3.39, 4.76 system payload, 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. eg.

tasks:115 Total, 1 running, sleeping, 0stopped, 0zombie
Cpu (s): 16.1% us, 2.0% sy, 0.0% ni, 79.5% ID, 1.4% wa, 0.0% Hi, 1.0% si

tasks:115 Total Process Totals
1 Running number of running processes
sleeping number of sleep processes
0 stopped stop process number
0 Zombie Number of zombie processes
CPU (s): 16.1% US user space consumes Cpu percentage
2.0% Sy percentage of CPU consumed by kernel space
0.0% CPU Percentage of processes that have changed priority within NI user process space
79.5% ID idle CPU percent
1.4% wa Wait for the input output CPU time percentage
0.0% hi
0.0% si

The last two behavior memory information. eg.

mem:8169876 k Total, 7686472 K used, 483404 K free, 35272 K buffers
swap:4096532 k Total, K-used, 4096372 K free, 2477532 K Cached

mem:8169876 ktotal Total Physical Memory
7686472 K used total amount of physical memory used
483404 k free memory Total
35272 k buffers memory used as the kernel cache
swap:4096532 k Total Total Swap partition
Total swap area used by used K
4096372 k Free swap area total
2477532 K 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, which 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.

Process information

The details of each process are shown below the statistics area. Let's start by understanding the meaning of the columns.

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

Ordinal column name meaning
pid    process ID
ppid    parent process ID
ruser    realusername
uid    The user ID of the process owner
user    The user name of the process owner
group    The group name of the process owner
tty    the terminal name of the startup process. Processes that are not started from the terminal are displayed as?
pr    Priority
ninice     value. Negative values indicate high priority, positive values indicate low priority
p    last used CPU, only make sense in multi-CPU environments
%cpu    CPU time consuming percentage last updated to current
Total CPU time used by the time    process, in seconds
time+    The total CPU time used by the process, in 1/100 seconds
%mem   Percent of physical memory used by the   process
The total amount of virtual memory used by the virt    process, in kilobytes. The Virt=swap+res
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
code    The physical memory size that executable code occupies, in kilobytes
data    the amount of physical memory that is consumed by parts other than executable code (data segment + stack) , Unit KB
shr    shared memory size, KB
nflt    page error
ndrt    last written to now, The number of pages that have been modified.

S process state.
d= non-disruptive sleep state
R= Run
S= Sleep
t= Tracking/Stopping
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

Sort by specified column

Top can be set to sort by an item, by default it is sorted by CPU usage,

M, (note upper case), sorted by memory usage

P, sort based on percent CPU usage

T, sorted by Time/accumulated time.

How to end a process

Enter the letter k(lowercase), and then enter the PID you want to kill

Of course you can also run the command directly, kill the PID

As you can see, the top command is a very powerful tool for monitoring systems and is especially important for system administrators. However, its disadvantage is that it consumes a lot of system resources.

II. FREE command

1. Role
The free command is used to display memory usage, and the use of permissions is for all users.

2. Format
free [-b-k-m] [-O] [-s delay] [-t] [-v]

3. 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.

4. Application examples
The free command is the primary command used to view memory usage. Compared to the top command, it has the advantage of being simple to use and consuming very little system resources. With the-s parameter, you can use the free command to continuously monitor how much memory is in use, which can be used as a handy real-time monitor.
#free-b-S5

With this command, the terminal continuously reports memory usage (in bytes), updated every 5 seconds.

Iii.Uptime Order
In the Linux system, there is a claim that when the load avarage <3 system is good, greater than 5 has serious performance problems. Note that this value should also be divided by the number of CPUs.

If load avarage=8, cpu=3,8/3=2.666,2.66 This value indicates that the system is in good condition
Greater than 5 is not necessarily a serious performance problem, it is possible that the host provides more than he can provide the ability to expand. To see specifically.

In addition, under Linux to see the utilization of system resources, there are two commands, respectively: Vmstat and Iostat. Interested friends, can also study under.

View Linux system Resource Usage commands (top, free, uptime)

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.