One Linux command top 12 per day

Source: Internet
Author: User
Tags set time terminates

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. Here is a detailed description of how it is used. Top is a dynamic display process where the current state can be refreshed continuously with the user key. If the command is executed in the foreground, it will monopolize the foreground until the user terminates the program. more accurately, The top command provides real-time status monitoring of the system's processor. It displays a list of the most "sensitive" tasks in the system. This command can be used by CPU. Memory usage and execution time to sort tasks, and many of the features of the command can be set through interactive commands or in personal customization files.

1. command format:

Top [parameters]

2. Command function:

Displays information about the processes currently being executed by the system, including process IDs, memory usage, CPU utilization, etc.

3. Command parameters:

-B Batch Processing

-C Displays the complete ruling command

-I ignores the failure process

-S Secret mode

-S cumulative mode

-i< time > Set time interval

-u< User name > Specify user name

-p< Process number > Specify process

-n< number of times > cycle display

4. usage Examples:

Example 1: Show Process Information

Command:

Top

Output:

[[email protected] log] # Top

1Top-14:06:23 up, 16:44, 2 users, load average:1.25, 1.32, 1.352tasks:206 Total, 1 running, 205 sleeping, 0 stopped, 0Zombie3Cpu (s): 5.9%us, 3.4%sy, 0.0%ni, 90.4%id, 0.0%wa, 0.0%hi, 0.2%si, 0%St4 mem:32949016k Total, 14411180k used, 18537836k free, 169884k buffers5 swap:32764556k Total, 0k used, 32764556k free, 3612636k cached6PID USER PR NI VIRT RES SHR S%cpu%MEM time+COMMAND728894 Root 0 1501m 405m 10m S 52.2 1.3 2,534:16Java818249 Root 0 3201m 1.9g 11m S 35.9 6.0 569:39.41Java92808 Root 0 3333m 1.0g 11m S 24.3 3.1 526:51.85JavaTen25668 Root 0 3180m 704m 11m S 14.0 2.2 360:44.53Java One574 Root 0 3168m 611m 10m S 12.6 1.9 556:59.63Java A1599 Root 0 3237m 1.9g 11m S 12.3 6.2 262:01.14Java -1008 Root 0 3147m 842m 10m S 0.3 2.6 4:31.08Java -13823 Root 0 3031m 2.1g 10m S 0.3 6.8 176:57.34Java the28218 Root 0 12760 1168 808 R 0.3 0.0 0:01.43Top -29062 Root 0 1241m 227m 10m S 0.3 0.7 2:07.32 Java

Statistical Information Area :

the first five elements are Current system situation statistical information of the whole Area . Let's look at the specific meaning of each line of information.

First line , task queue information, execution results with the uptime command , the specific parameters are described as follows:

14:06:23-Current system time

up + days, 16:44-the system is already running - days - hours - minutes (during this time the system did not restart the yo!) )

2 users-currently has 2 users logged into the system

The three numbers behind the load average:1.15, 1.42, 1.44-load average are 1-minute, 5-minute, 15-minute loads respectively.

The load average data is the number of active processes that are checked every 5 seconds and then calculated by a particular algorithm. If this number is divided by the number of logical CPUs, the result above 5 indicates that the system is overloaded.

Second Line , tasks-Task (process) , the specific information is described as follows:

system is now common 206 process, which is running in 1, 205 There are 0 of the 0, zombie States (Zombies) in Sleep (sleep), stoped states.

the third line, CPU Status information, the specific properties are described below:

5.9%us-the percentage of CPU occupied by the user space.

3 . 4% sy-The percentage of CPU consumed by the kernel space.

0.0% ni-The percentage of CPU that has changed the priority of the process

9 0.4 % id-Idle CPU percentage

0.0% Wa-io waiting for CPU percentage

0.0% hi-Hard Interrupt (Hardware IRQ)% of CPU occupied

0.2% si-soft interrupt (software interrupts)% of CPU occupied

remark: The CPU usage ratio here differs from the Windows concept, need to Understanding Linux Systems user space and kernel space the relevant knowledge!

Line Fourth , Memory State , the specific information is as follows:

32949016k total-Total Physical memory (up toGB)

Total Memory in 14411180k used-in use (GB)

18537836k free-Total free memory (18GB)

169884k buffers-cache memory (169M)

Line Fifth, Swap swap partition information, specific information is described below:

Total 32764556k total-swap area ( 3 2GB)

0 total number of swap areas used by K used-( 0K )

32764556k free-total idle swap area (32GB)

3612636k cached-buffered swap area total (3.6GB)

Note:

The total amount of memory in use in row four (used) refers to the amount of memory that is now controlled by the system kernel, and the total amount of free memory that the kernel has not included in its control range. The memory that is included in kernel management is not always in use, but also includes the memory that has been used in the past that can now be reused, and the kernel does not return these reusable memory to free, so there is less memory on Linux, but don't worry about it.

If you are accustomed to calculating the number of available memory, here is an approximate formula: The fourth line of Free + fourth row buffers + fifth row of cached, press this formula for this server's available memory: 18537836k  + 169884k  + 3612636k = around 22GB.

For memory monitoring, in the top we have to monitor the fifth line swap partition used, if this value is constantly changing, indicating that the kernel is constantly in memory and swap data exchange, which is really not enough memory.

Line six, blank line.

Line seventh below: status monitoring of each process (task), the project column information is described as follows:

pid-Process ID

user-Process Owner

pr-Process Priority

The Ni-nice value. Negative values indicate high priority, positive values indicate low priority

The total amount of virtual memory used by the virt-process, in kilobytes. Virt=swap+res

The size, in kilobytes, of the physical memory used by the res-process and not swapped out. Res=code+data

shr-shared memory size, in kilobytes

S-process state. d= non-disruptive sleep status r= run s= sleep t= track/stop z= zombie Process

%cpu-percentage of CPU time that was last updated to current

Percentage of physical memory used by the%mem-process

Total CPU time used by the time+-process, Unit 1/100 sec

command-Process Name (command name/command line)

Other tips for use:

1. Multi-u multi-core CPU monitoring

In the top basic view, press the keypad number "1" to monitor the status of each logical CPU:

observe that the server has 16 logical CPUs, which are actually 4 physical CPUs. Press the number key 1 again to return to the top basic view interface.

2. Highlight the current running process

tap the keyboard "B" (Turn on/off the highlight effect) and the top view changes as follows :

We found that the "top" process with process ID 2570 was highlighted, and the top process was the only running state (runing) that was shown in the second row of the view, and you could turn off or turn on the highlight of the running process by tapping the "Y" key.

3. process Field sorting

By default, when Top is reached, the processes are sorted according to CPU consumption, with the process ID 28894 of the Java process First (CPU 142%), and the process ID 574 Java process second (CPU occupied 16%).

Tap the keyboard "X" (The highlight effect on/off the row sequence), and the top view changes as follows:

 

As you can see, the top default sort column is "%cpu".

4. You can change the column to the right or left by using "SHIFT + >" or "Shift + <"

is to press SHIFT + > once, the view is now sorted by%mem.

Example 2: Show full Command

Command:

Top-c

Output:

Description

Example 3: Displaying program information in batch mode

Command:

Top-b

Output:

Description

Example 4: displaying program information in cumulative mode

Command:

Top-s

Output:

Description

Example 5: set Information update times

Command:

top-n 2

Output:

Description

Indicates update two times after the update display is terminated

Example 6: Set Information update time

Command:

Top-d 3

Output:

Description

Indicates an update period of 3 seconds

Example 7: Displaying the specified process information

Command:

Top-p 574

Output:

Description

5. Top Interactive Commands

Some of the interactive commands that you can use during the top command execution. These commands are single-letter, and some of these commands may be masked if the S option is used on the command line.

H Display the help screen and give some brief command summary instructions

K Terminates a process.

I ignore idle and zombie processes. This is a switch-type command.

Q Exit Program

R reschedule a process's priority level

S Switch to cumulative mode

s change the delay time between two refreshes (in units of s), and if there are decimals, convert to M S. Enter 0 value and the system will refresh continuously, the default value is 5 s

F or F Add or remove items from the current display

O or O change the order in which items are displayed

L Toggle display of average load and start-up time information

M Toggle Display Memory Information

T toggle display of process and CPU status information

C Toggle Display command name and full command line

M sort based on resident memory size

P Sort by percentage of CPU usage

T Sort by Time/cumulative time

W writes the current settings to the ~/.TOPRC file  

One Linux command top 12 per day

Related Article

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.