Linux command detailed top system resource detection

Source: Internet
Author: User
Tags terminates cpu usage

instruction: Top continuous monitoring of the entire system's program working status

<1>.top is an excellent interactive tool that can display real-time information about the current system's processes, including PID, memory occupancy, CPU occupancy, and so on, sorted by CPU usage, and memory utilization.
<2> If the command is executed in the foreground, it will always display the foreground until the user terminates the program

Command format:
# top [-] [d] [P] [Q] [C] [C] [s] [s] [n]

Parameter description:
-B: Batch processing mode. Often used in scripts, the output of the message-C: Displays the command line containing the path, not just the program name-D: Specifies the time interval for information refresh (default is 5s)-I: Do not show idle or zombie process-N: Specifies the number of times to display. Typically with-B use-P: Specifies the process number. You can specify multiple pid-s: Enable the top command to run in Safe mode-S: Specify the cumulative mode, the CPU time per process for the process and the time that the closed child process locks accumulate-u: Specify user name

Top Interactive commands:
C: Show full command d: Change refresh frequency f: Increase or decrease the columns to be displayed (the selected will be capitalized with the * number) F: Select sorted column H: Display Help screen h: Show thread I: ignore idle and zombie process K: terminates a process by giving a PID and a signal. (The default signal is 15.) This command is masked in Safe mode) L:  Show average load and start time (that is, show Shadow First row) m: Display memory information m: Sort based on memory resource usage size n: Rank by PID from high to low o: Change the Order of column display o: Select the sorted column, exactly the same as F P: Sort by CPU Resource usage size Q: Exit the top command r: Modifies the Nice value (priority) of the process. The priority defaults to 10, the positive value decreases the priority, and the higher priority s: Sets the refresh frequency (the default unit is seconds, and if a decimal number is converted to MS). The default value is 5s, enter a value of 0, the system will constantly refresh S: Cumulative mode (the CPU time occupied by the completed or exited subprocess is accumulated to the parent process's mite+) T: Sort T: Displays process and CPU status information (that is, display shadow CPU rows) U: Specify user process W: Write the current settings to the ~/.TOPRC file, and the next time you start to automatically invoke the settings of the TOPRC file <: page forward;: Show help Screen 1 (number 1): Show details of each CPU <space>: Refresh Now


Top output parsing
# Top
top-02:53:08 up, 18:47,  1 user,  load average:0.02, 0.01, 0.00Tasks:   1 running,  83 Sleeping,   0 stopped,   0 zombiecpu (s): 0.0%us,  0.2%sy,  0.0%ni, 99.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%stmem:   3922748k Total,   813552k used,  3109196k free,   158292k Buffersswap :  8191992k Total,        0k used,  8191992k free,   505676k cached  PID USER      PR  NI  VIRT  RES  SHR S%cpu%MEM    time+  COMMAND                                                                                                                                                                          1086 root   0 15004 1292 1004 R  0.3  0.1   0:00.11 top                                                       1 root   0 19232 1476 1188 S  0.0  0.0   0:00.67 Init
First line:
top-02:53:08 up, 18:47, 1 user, load average:0.02, 0.01, 0.00
Top: The instruction represented as top
02:53:08: System Current time
Up to Days, 18:47: How much time the system has been booting up to now
1 User: Current number of connected users
Load average:0.02, 0.01, 0.00: Average CPU Load information for the system 1 minutes, 5 minutes, 15 minutes

system average CPU load:
<1>.load average data checks the number of active processes every 5 seconds and then calculates the values by a specific algorithm.
&LT;2&GT; In multiprocessor systems, the CPU load average is determined based on the number of cores. With a 100% load, 1.00 represents a single processor, while 2.00 indicates that there are two dual processors, and 4.00 means that the host has four processors. For a dual-core processor, a value of 2.00 indicates a 100% load.
<3> Generally, this value should be less than 1 for a single processor, unless the system is busy. A value above 5 indicates that the system is overloaded.
<4> An experienced system administrator will draw this line at 0.70:

Second Line: Task overview
tasks:84 Total, 1 running, sleeping, 0 stopped, 0 zombie
Tasks: Task
Total: Current number of processes
1 Running: Number of running processes
Sleeping: Number of sleep processes
0 stopped: Number of processes stopped
0 Zombie: Zombie Process Count

Third line: CPU status indicates that this line shows CPU overall information
Cpu (s): 0.0%us, 0.2%sy, 0.0%ni, 99.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
CPU (s): Displays information about the CPU
US: User space consumes CPU percentage
Sy: Percentage of CPU consumed by kernel space
NI: CPU percentage of processes that have changed priority in user process space
ID: Percentage of idle CPU (reflects the busy level of a system CPU)
WA: Percentage of CPU time waiting for input output (I/O)
HI:CPU processing time of hardware interrupt consumption
Si:cpu How long it takes to handle software outages
ST: Displays the CPU time that the virtual machine was hypervisor stolen (with virtual CPUs)

Note:When there are multiple CPUs, there may be more than two lines, this time you need to use the number keys to change, as follows
Cpu0  :  0.7%us,  0.0%sy,  0.0%ni, 99.3%id,  0.0%wa,  0.0%hi  , 0.0%si, 0.0%STCPU1 :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st

Line four: Physical memory usage
mem:3922748k Total, 813552k used, 3109196k free, 158292k buffers
Men: displaying memory information
Total: Indicates the amount of physical memory (totals = used + Free)
Used: Indicates the total amount of physical memory already in use
Free: Indicates idle physical memory (buffers and cached are also used as consumed)
Buffers: Represents the physical memory used as the kernel cache

Line five: Virtual memory usage (swap space)
swap:8191992k Total, 0k used, 8191992k free, 505676k cached
Swap: Swap space
Total: Indicates the amount of swap space
Used: Indicates the total amount of swap space used
Free: Indicates the total amount of idle swap space
Cached: Indicates the total amount of buffer swap space

Both buffers and cached are the underlying mechanisms of the Linux operating system to speed up access to the disk.
Where buffers refers to the read-write buffer of a block device, cached refers to the page cache of the file system itself.

Approximate total calculated memory formula: line Fourth of free + fourth line buffers + fifth row of Cached

Line six: blank line
Where to enter instructions in the top program

Line seventh: Resource Usage per process
  PID USER      PR  NI  VIRT  RES  SHR S%cpu%MEM    time+  COMMAND                                                                                                                                                                          1086 root   0 15004 1292 1004 R  0.3  0.1   0:00.11 top                                                                                                             1 root   0 19232 1476 1188 S  0.0  0.0   0:00.67 Init
PID:  ID of the process (unique identifier of the process) User: The process's   priority (the smaller the value is executed, the RT represents the running) NI:   The nice value of the process. (range 20 to 19, the smaller the value, the higher the priority is performed) VIRT: Total amount of virtual memory used by the process (unit kb,virt=swap+res) RES:  The physical memory occupied by the process. (in kilobytes.) Res=code+data. %MEM shows the value of this column) SHR:  shared memory used by the process. (in kilobytes) S:    The state of the process. There are mainly the following types:    D. Non-interruptible sleep    S. Hibernate    R. Running    T. Being tracked or stopped    Z. Zombie State (Zombies process)%cpu: The percentage of CPU that the process consumes%mem: The percentage of physical memory that the process consumes (as the value of the Res column is the standard) Time+: The total CPU time that is consumed after the process starts. (Unit 1/100 sec) Command: Process start name


There are other outputs that are not displayed by default, and all are displayed as follows
A   PID     process IDB   PPID    Parent process IDC   ruser   Real user named   UID     Process owner users IDE    The user name of the process owner the   group name of the F group Process owner G   TTY     initiates the terminal name of the process. H   PR      priority i   NI nice      value. Negative value indicates high priority, positive value indicates       the last CPU used by low priority J P, only meaningful in multi-CPU environment K   %CPU    Last updated to current CPU time consumption percent L    Total CPU time used by the process, per second m   time+   The total CPU time used by the process, 1/100 seconds n   %MEM    The percentage of physical memory used by the process o   VIRT    The total amount of virtual memory used by the process, in kilobytes. The Virt=swap+resp   swap    process uses the amount of virtual memory that is swapped out, in kilobytes. Swap = The     amount of physical memory, in kilobytes, that is used by the Virt-resq RES process and not swapped out. Res=code+data (application really uses memory) r code    executable code occupies the physical memory size, the unit KBS   data    executable code other than the portion (data segment + stack) occupies the physical memory size, Unit KBT   SHR     shared memory size, unit KBU    The number of page faults that have occurred since the Nflt process was started (this value is too high for the process to read a large amount of resources from disk) v   ndrt    The number of pages that were last written to the page that has now been modified. (usually less than 10 or 0) W   S       process status        D. Non-interruptible sleep        S. Hibernate        R. Running        T. Being tracked or stopped        Z. Zombie State (Zombies process) x   Command name/command line y   Wchan   If the process is sleeping, the system function name in sleep is displayed z   flags   task flag, reference sched.h

Note:
<1> In the default, it is sorted by "%cpu".
<2>.shift + > or SHIFT + < can change the column to the right or left
<3> When the refresh time needs to be faster than 1s: more samples in the time period

-------------------------------
Parameter instance
1. Default output:
# Top

2. Specify the number of outputs (-N)
Update 5 times after exiting
# top-n 5

3. Batch processing mode (-B)
Use batch mode to save output in a file
# Top-b

4, 2 and 3 combined:
Processing top information 5 times and then outputting the result to the Dodo.txt file
# Top-b-N 5 >/doiido/dodo.txt

5. Specify process (-p)
PID 0 represents the PID of the top command itself
5.1: Monitor the PID 3345 process
# top-p 3345

5.2: Monitor PID 3345 and PID 7634 process
# top-p 3345-p 7634

6. Specify the refresh time (-D) (in seconds)
Set information refresh time to 5s (typically set to 1-3 second interval)
# top-d 5

7. Display full command (-c)
# top-c

8. Display information in cumulative mode (-s)
# top-s

9. Specify user name (-u,-u)
You can specify the user or UID to display
9.1, only show the process of user as Doiido
# top-u Doiido

9.2. Only the process with UID 600 is displayed.
# top-u

Note:the-P,-U, and-u options can use only one

10. Show Idle Process only (-i)
# top-i

-------------------------------
Interactive command Instances
1. Help:h or?

2, immediately refresh:<ENTER> or <SPACE>

3. Set Update refresh interval:' d ' or ' s '
When you press ' d ' or ' s ', you will be prompted for a value (in seconds), and the value will be used as the refresh interval

4. Field Management:F
Press F to select the field you want to display. (* mark indicates selected)

5. Reverse Order:R
Press R to toggle reverse and general sorting

6. Show Command:C
Press C to toggle the full path and program name

7. Idle tasks:I
Toggle display of idle tasks

8. Designated Users:u
Pressing u prompts for a user name and then displays the process for a specific user (blank will show all users)

9, Bold display:B
Press B to toggle important information in bold display

10. Set maximum display task number:' n ' or ' # '
When you press N or #, you are prompted to enter a number, which is the maximum number of tasks displayed.

11. The process of termination:k
After pressing K, you will be prompted to enter a PID, and then input the PID will be prompted to enter what signal to the process
Note: The general termination process uses a 15 signal, and if it does not end normally the signal is used 9

12. Toggle Highlight Information:' x ' or ' Y '
x: Highlighting the sorted character (column)
Y: Highlight the running process (rampage)

13. Re-set Priority:R
Reset the priority of a task (same usage as K)

14, switch load, task, memory information display:' l ' t ' m '
The default is as follows:
Top-09:32:20 up-min,  1 user,  load average:0.00, 0.00, 0.00Tasks: Total  ,   1 running,  sleepin G,   0 stopped,   0 zombiecpu (s):  0.0%us,  0.5%sy,  0.0%ni, 99.5%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%stmem:   1914492k Total,   148084k used,  1766408k free,     7460k Buffersswap:  2047992k Total,        0k used,  2047992k free,    37928k Cached

L: Toggle Show Second Line
Tasks: Total  ,   1 running,  sleeping,   0 stopped,   0 zombiecpu (s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%stmem:   1914492k Total,   148084k Used,  1766408k free,     7452k buffersswap:  2047992k Total,        0k used,  2047992k free,    37928k Cached

T: Toggle to display the third row
top-09:32:46 up-min,  1 user,  load average:0.00, 0.00, 0.00Mem:   1914492k Total,   148084k used,
   1766408k free,     7460k buffersswap:  2047992k Total,        0k used,  2047992k free,    37928k Cached

M: Toggle display mem and swap
top-09:33:32 up min,  1 user,  load average:0.00, 0.00, 0.00Tasks: All  ,   1 running, +  SL Eeping,   0 stopped,   0 zombiecpu (s):  0.0%us,  0.5%sy,  0.0%ni, 99.5%id,  0.0%wa  , 0.0%hi,  0.0%si,  0.0%st

15. Switch between full screen and alternating mode:A
Alternating mode press A will display 4 windows, each of the following four fields:
DEF: Default field group (only this group is shown by default)
Job: Task field group
Mem: Memory field group
USR: User field group
In this mode, pressA or WYou can toggle, then press-Can hide
:D ef-09:23:09 Up-min, 1 user, Load average:0.00, 0.00, 0.00tasks:72 Total, 1 running, sleeping, 0 Stoppe D, 0 zombiecpu (s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%stmem:1914492k total, 147960 K used, 1766532k free, 7380k buffersswap:2047992k total, 0k used, 2047992k free, 37928k cached1 PID use      R PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND 1 root     0 19232 1516 1228 S 0.0 0.1 0:01.08 init 2 root 20 0                                                                                      0 0 0 S 0.0 0.0 0:00.00 Kthreadd                                              2 PID PPID time+%cpu%MEM PR NI S VIRT SWAP RES UID COMMAND 1086 1073 0:01.70 0.0 0.1 0 R 15004 0 1296 0 Top 10 73 1069 0:00.03 0.0 0.1 0 S 105m 0 1844 0 Bash 3 PID%MEM VIRT SWAP RES CODE DATA SHR nflt ndrt S PR NI%cpu COMMAND 1069 0.     2 98.0m 0 4028 520 3048 5 0 S 0 0.0 sshd 1034 0.2 81520     0 3424 288 704 2544 2 0 S 0 0.0 qmgr 4 PID PPID UID USER      Ruser TTY time+%cpu%MEM S COMMAND 1069 949 0 root root          ?          0:00.94 0.0 0.2 S sshd 1025 1 0 root root?   0:00.01 0.0 0.2 S Master

------------------------Specific Applications------------------
1: Monitoring through shell scripting
Add the following line in the shell script
top-b-N 2 | grep-e "java| Apache2 ">>/doiido/logs

2: Monitor specific processes
Save the process command-line feature you want to monitor in the keys
#!/bin/shkeys= ' Agent|omc4j|terminal|module ' PsList () {    ps-ef | egrep $KEYS | grep-v grep}readpid () {while    read User PID dummy;    Do        echo-n "-P $pid"    done}top ' pslist | readpid '

3. Take a snapshot of the Resource usage state at a specific time, in conjunction with at or cron
# VI test.at
Term=linux top-b-N 1 >/doiido/dodo.txt
# at-f./test.at now+1minutes

This variable is required by the Term:top runtime, but "at" does not persist on a timed call

4. View run time
# time Top-b-N 1
Real    0m0.665suser    0m0.010ssys     0m0.108s

Real:top total time required for work



Linux command detailed top system resource detection

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.