Linux Command details: top system resource detection, linuxtop

Source: Internet
Author: User

Linux Command details: top system resource detection, linuxtop
Command: top continuously monitors the program working status of the entire system

<1>. top is an excellent interactive tool that can display the process information of the current system in real time, including PID, memory usage, CPU usage, etc, you can also sort by CPU usage and memory usage as needed.
<2>. If you execute this command on the foreground, it displays 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. Usually used in scripts, constantly output information-c: display the command line containing the path, not just the program name-d: Specifies the interval of Information refresh (default is 5 s) -I: do not show idle or dead processes-n: specifies the number of times displayed. Generally, use-p with-B to specify the process number. You can specify multiple PIDs-s to run the top Command in safe mode-S: Specify the cumulative mode, the CPU time of each process is the accumulated time of the process and the disabled sub-process lock-u: Specify the user name

Top interactive commands:
C: display the complete command d: Change the refresh frequency f: add or remove the columns to be displayed (the selected columns will be capitalized and the * sign will be added) F: select the sorted column h: display help screen H: display thread I: Ignore idle and dead processes k: terminate a process by giving a PID and a signal. (The default value is signal 15. In security mode, this command is blocked.) l: display the average load and start time (that is, display the first line of shadow) m: display the memory information M: sort by memory resource usage N: sort by PID from high to low o: change the sequence of Column Display O: select the column to be sorted, exactly the same as f p: sort by CPU resource usage. q: exit the top Command. r: Modify the nice value (priority) of the process ). The default priority is 10, and the positive value reduces the priority. Otherwise, the priority s is increased. Set the refresh frequency (the default unit is seconds. If there is a decimal number, it is converted to ms ). The default value is 5 s. If the input value is 0, the system will continuously refresh S: accumulative mode (accumulates the CPU time occupied by completed or exited sub-processes to the MITE + of the parent process) T: sort by the CPU usage time of a process. t: displays the process and CPU status information (that is, displays the shadow CPU Line). u: Specifies the user process. W: writes the current settings ~ /. The toprc file will automatically call the settings of the toprc file at the next Startup <: turning the page forward>: turning the page backward? : Display help screen 1 (number 1): displays the details of each CPU <Space>: refresh immediately


Top output Parsing
# Top
top - 02:53:08 up 24 days, 18:47,  1 user,  load average: 0.02, 0.01, 0.00Tasks:  84 total,   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      20   0 15004 1292 1004 R  0.3  0.1   0:00.11 top                                                       1 root      20   0 19232 1476 1188 S  0.0  0.0   0:00.67 init
The first line:
Top-02:53:08 up 24 days, 1 user, load average: 0.02, 0.01, 0.00
Top: indicates the top command.
02: 53: 08: current system time
Up 24 days, 18: 47: How long has the system been started?
1 user: current number of connected users
Load average: 0.02, 0.01, 0.00: average CPU load information of the system for 1 minute, 5 minutes, and 15 minutes

Average system CPU load:
<1> load average data checks the number of active processes every five seconds, and then calculates the number based on a specific algorithm.
<2> in a multi-processor system, the average CPU load is determined by the number of cores. In 100% load computing, 1.00 represents a single processor, while 2.00 represents two dual processors. Similarly, 4.00 indicates that the host has four processors. For a dual-core processor, if the value is 2.00, the load is 100%.
<3>. Generally, this value should be lower than 1 for a single processor unless the system is busy. If this value is greater than 5, the system is overloaded.
<4> experienced system administrators can drag this line to 0.70:

Row 2: Task Overview
Tasks: 84 total, 1 running, 83 sleeping, 0 stopped, 0 zombie
Tasks: Task
84 total: total number of processes
1 running: Number of running Processes
83 sleeping: Number of sleep Processes
0 stopped: Number of stopped Processes
0 zombie: Number of zombie Processes

Row 3: cpu status indicates that this line shows the overall CPU 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 CPU Information
Us: CPU usage of user space
Sy: CPU usage percentage of kernel space
Ni: CPU usage of processes that have changed their priorities in user process space
Id: Percentage of idle CPU (reflecting the idle cpu usage of a System)
Wa: Percentage of CPU time waiting for input/output (I/O)
Hi: CPU processing time occupied by hardware interruption
Si: CPU processing software interruption time
St: displays the CPU time when the VM is stolen by the hypervisor (when there is a virtual cpu)

Note: When multiple CPUs exist, there may be more than two rows. In this case, you need to use the number key 1 to change the number, as shown below:
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

Row 4: physical memory usage
Mem: 3922748 k total, 813552 k used, 3109196 k free, 158292 k buffers
Men: displays memory information.
Total: total physical memory (total = used + free)
Used: total physical memory used
Free: indicates the idle physical memory (buffers and cached are also used)
Buffers: indicates the physical memory used as the kernel Cache

Row 5: virtual memory usage (swap space)
Swap: 8191992 k total, 0 k used, 8191992 k free, 505676 k cached
Swap: Swap space
Total: indicates the total swap space.
Used: indicates the total amount of swap space used.
Free: indicates the total amount of free swap space.
Cached: indicates the total amount of buffer swap space.

Both buffers and cached are underlying mechanisms of the linux operating system to accelerate disk access.
Where buffers refers to the block device's read/write buffer, and cached refers to the page cache of the file system itself.

Formula for Calculating the total memory size: free in the fourth row + buffers in the fourth row + cached in the fifth row

Row 6: Empty rows
Where the command is entered in the top Program

Row 7: resources used by each process
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                                                          1086 root      20   0 15004 1292 1004 R  0.3  0.1   0:00.11 top                                                                                                             1 root      20   0 19232 1476 1188 S  0.0  0.0   0:00.67 init
PID: process ID (Unique Identifier of the Process) USER: USER of the Process PR: Priority of the Process Scheduling (the smaller the value, the higher the execution priority, RT indicates that the process is running) NI: nice value of the process. (The value ranges from-20 to 19, and the smaller the value, the higher the execution priority) VIRT: Total virtual memory used by the process (unit: kb, VIRT = SWAP + RES) RES: physical memory occupied by the process. (Unit: kb. RES = CODE + DATA. % MEM displays the value of this column) SHR: shared memory used by the process. (Unit: kb) S: the status of the process. There are mainly the following types: D. uninterrupted sleep S. sleep R. running T. tracked or stopped Z. zombie process % CPU: Percentage of CPU occupied by the process % MEM: Percentage of physical memory occupied by the process (based on the RES column value) TIME +: the total CPU time occupied by the process after it is started. (Unit: 1/100 seconds) COMMAND: name of the Process startup COMMAND


There are other outputs not displayed by default, all of which are shown as follows
A PID process idb PPID parent process idc RUSER Real user named UID process owner USER ide user process owner USER name f GROUP process owner GROUP name g tty start process terminal name. H PR priority I NI nice value. A negative value indicates a high priority. A positive value indicates the CPU used at the low priority j P, only meaningful k % CPU usage percentage of cpu time last updated to the present in multi-CPU environment l total cpu time used by the TIME process, in seconds m TIME + total cpu time used by the process, unit: 1/100 seconds n % MEM percentage of physical memory used by the process o total virtual memory used by the VIRT process, unit: kb. VIRT = SWAP + RESp in the virtual memory used by the SWAP process, the size of the SWAP, in kb. SWAP = physical memory used by the VIRT-RESq RES process and not swapped out, in kb. RES = CODE + DATA (memory used by the Application) The physical memory occupied by the executable CODE of r CODE, in units other than the executable CODE of kbs DATA (DATA segment + stack) the size of the physical memory occupied. The unit is kbt SHR shared memory. The number of page errors since the Unit is kbu nFLT. (This value is too high, meaning that the process reads a large amount of resources from the disk) the number of modified pages written to the last time by v. (Usually less than 10 or 0) w S Process status D. uninterrupted sleep S. sleep R. running T. tracked or stopped Z. dead state (zombie process) x COMMAND name/COMMAND line y WCHAN if the process is sleeping, the system function name z Flags task mark in sleep is displayed. For details, refer to sched. h

Note:
<1>. By default, it is sorted by "% CPU"
<2>. shift +> or shift + <you can change the sorting column to the right or left.
<3>. When the refresh time needs to be faster than 1 s: more samples are needed within the time range.

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

2. specify the number of outputs (-n)
Exit after 5 updates
# Top-n 5

3. batch processing mode (-B)
You can save the output in the file in batch mode.
# Top-B

4, 2 and 3 combined:
Process the topic information 5 times, and then output the result to the dodo.txt file.
# Top-B-n 5>/doiido/dodo.txt

5. Specify the process (-p)
PID 0 indicates the pid of the top command.
5.1: monitor processes with a PID of 3345
# Top-p 3345

5.2: monitor processes with PID 3345 and PID 7634
# Top-p 3345-p 7634

6. Specify the refresh time (-d) in seconds)
Set the information refresh time to 5 s (usually set to the interval of 1 to 3 seconds)
# Top-d 5

7. display the complete command (-c)
# Top-c

8. display information in cumulative mode (-S)
# Top-S

9. Specify the user name (-u,-U)
You can specify the displayed user or UID
9.1 display only processes whose users are doiido
# Top-U doiido

9.2. Only processes whose UID is 600 are displayed
# Top-u 600

Note: The-p,-u, and-U options can only use one

10. Only idle processes (-I) are displayed)
# Top-I

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

2. Refresh now: <ENTER> or <SPACE>

3. Set the update interval: 'D' or 'S'
When you press 'D' or 'S', you will be prompted to enter a value (in seconds), which will be used as the refresh interval.

4. Field Management: f
After pressing f, you can select the field to be displayed. (* Mark indicates selected)
 
5. Reverse sorting: R
Switch reverse and general sorting by pressing R

6. Display command: c
Press c to switch the complete path and program name

7. Idle task: I
Switch to show idle tasks

8. specified user: u
Press u to prompt you to enter the user name, and then the process of the specific user will be displayed (blank will show all users)

9. Bold: B
Press B to switch to the important information in bold.

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

11. Terminated process: k
After you press k, you will be prompted to enter a PID. After you enter the PID, you will be prompted to enter the signal to the process.
Note: Generally, 15 signals are used to terminate a process. If the process cannot end normally, 9 signals are used.

12. Switch the highlighted information: 'X' or 'y'
X: highlight the sorting field (column)
Y: highlight running processes (horizontal)

13. Reset the priority: r
Reset the priority of a task (same as k)

14. display of switching load, task, and memory information: 'l't'm'
The default value is as follows:
top - 09:32:20 up 26 min,  1 user,  load average: 0.00, 0.00, 0.00Tasks:  72 total,   1 running,  71 sleeping,   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: Switch to display the second line
Tasks:  72 total,   1 running,  71 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: Switch to display the third line
top - 09:32:46 up 26 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: Switch display Mem and Swap
top - 09:33:32 up 27 min,  1 user,  load average: 0.00, 0.00, 0.00Tasks:  72 total,   1 running,  71 sleeping,   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. switching between full screen and alternate mode:
In alternate mode, press A to display four windows, which are the following fields:
Def: Default field group (only this group is displayed by default)
Job: Task field group
Mem: memory field group
Usr: User field group
In this mode, you can switch by a or w. After switching, press-to hide
:Def - 09:23:09 up 17 min,  1 user,  load average: 0.00, 0.00, 0.00Tasks:  72 total,   1 running,  71 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,   147960k used,  1766532k free,     7380k buffersSwap:  2047992k total,        0k used,  2047992k free,    37928k cached1  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                   1 root      20   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  20   0 R 15004    0 1296    0 top                                                  1073  1069   0:00.03  0.0  0.1  20   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  800 3048    5    0 S  20   0  0.0 sshd                                             1034  0.2 81520    0 3424  288  704 2544    2    0 S  20   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 application ------------------
1: shell script monitoring
Add the following lines to the shell script:
Top-B-n 2 | grep-E "java | apache2">/doiido/logs

2: monitor specific processes
Save the command line feature of the process to be monitored to 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. Works with at or cron to take a snapshot of the resource usage status at a specific time.
# Vi test.
TERM = linux top-B-n 1>/doiido/dodo.txt
# At-f./test. at now + 1 minutes

TERM: This variable is required for Top running, but "at" is not retained during scheduled calls.

4. view the running time
# Time top-B-n 1
real    0m0.665suser    0m0.010ssys     0m0.108s

Real: Total time required for Top jobs



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.