Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the top command to analyze system performance in linux

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use the top command in linux to analyze system performance, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

A brief introduction to the top command of linux

Top command is a commonly used performance analysis tool under Linux, which can display the resource consumption of each process in the system in real time, similar to the task manager of Windows.

Top displays the current process and other conditions of the system, which is a dynamic display process, that is, the current state can be constantly refreshed by the user's key press. If the command is executed at the foreground, it will monopolize the foreground until the user terminates the program. More accurately, the top command provides real-time monitoring of the status of the system processor. It will display a list of CPU's most sensitive tasks in the system. This command can be used by CPU. Memory usage and execution time sort tasks; and many of the features of this command can be set through interactive commands or in personal customization files.

In the linux system, the top command is the most convenient tool to analyze system performance, and top is also an interactive tool; through the top command, we can clearly understand the information of the executing process, including process ID, memory occupancy, CPU occupancy and so on. It's actually similar to window's task manager.

The result of running the top command is as follows:

The first line is the task queue information, which is similar to the execution result of the uptime command. The specific parameters are described as follows:

19:40:19-indicates the current system time

Up 35 days, 20:32-indicates that the system has been running for 35 days, 20 hours and 32 minutes.

1 users-1 user is currently logged in to the system

Load average: 0.00,0.00,0.00-load average followed by 1 minute, 5 minutes and 15 minutes of load, respectively.

Load average data is the number of active processes checked every 5 seconds and then calculated according to a specific algorithm. If this number is divided by the number of logical CPU, a result higher than 5 indicates that the system is overloaded.

The second line, Tasks-Task (process), the specific information is as follows:

The system now has a total of 81 processes, including 1 running, 80 in sleep, 0 in stoped, and 0 in zombie (zombie). Pay special attention to zombie processes.

The third line, cpu status information. The specific attributes are described as follows:

0.0%us-percentage of CPU occupied by user space.

0.0%sy-percentage of CPU occupied by kernel space.

0.0%ni-percentage of CPU occupied by processes that have changed priority

100.0%id-percentage of idle CPU

Percentage of CPU occupied by 0.0%wa-IO waiting

0.0%hi-percentage of CPU occupied by hard interrupt (Hardware IRQ)

0.0%si-percentage of CPU occupied by soft interrupt (Software Interrupts)

0.0%st-I don't know.

The fourth line, Mem memory status. The details are as follows:

1029828k total-Total physical memory (1GB)

804628k used-Total memory in use (767m)

228200k free-Total free memory (217m)

167208k buffers-amount of cached memory (159m)

On the fifth line, swap exchanges partition information. The details are as follows:

0k total-Total exchange area (0K)

0k used-Total number of swap areas used (0K)

0k free-Total free swap area (0K)

401672k cached-Total number of swap areas buffered (383m)

The sixth line, blank line.

The seventh line is as follows: status monitoring of each process (task). The column information is as follows:

PID-process id

USER-process owner

PR-process priority

NI-nice value. Negative values indicate high priority, while positive values indicate low priority.

VIRT-the total amount of virtual memory used by the process, in kb. VIRT=SWAP+RES

RES-the amount of physical memory used by the process that has not been swapped out, in kb. RES=CODE+DATA

SHR-shared memory size in kb

S-process status. D = uninterruptible sleep state R = run S = sleep T = track / stop Z = zombie process

% CPU-percentage of CPU time elapsed since last update

% MEM-percentage of physical memory used by the process

TIME+-Total CPU time taken by the process (in 1100s)

COMMAND-process name (command name / command line)

Top command parameters:

-b batch processing

-c displays the full COMMAND

-I ignore the failure process

-s security mode

-S accumulation model

-I set the interval

-u specify user name

-p specify the process

The number of times the-n loop is displayed

Interactive commands for top (just enter the following command while the top command is running):

Q: exit the program.

H or?: show the help screen and give some short summary instructions for the command.

K: terminates a process. The user will be prompted to enter the process PID that needs to be terminated and what kind of signal needs to be sent to the process. A general termination process can use a 15 signal; if it does not end properly, use signal 9 to force the process to end. The default value is signal 15. This command is blocked in safe mode.

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

M: sort according to the resident memory size.

P: sort according to the percentage of CPU usage.

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.

R: rearrange the priority of a process. The user is prompted to enter the process PID that needs to be changed and the process priority value to be set. Entering a positive value lowers the priority, otherwise it gives the process a higher priority. The default value is 10.

L: toggle to display average load and startup time information. That is, the first line of the shadow collection is displayed

M: toggles the display of memory information. That is, the shadow memory line is displayed

T: toggles the display of process and CPU status information. That is, display the shadow CPU line

C: toggles the display command name and the full command line. Displays the complete command. This feature is very useful.

S: switch to cumulative mode.

S: change the delay time between refreshes. The user will be prompted to enter a new time in s. If there is a decimal, it is converted to ms. Enter a value of 0 and the system will continue to refresh, with a default value of 5s. It should be noted that if you set too little time, it is likely to cause continuous refresh, so that it is too late to see the display at all, and the system load will be greatly increased.

F or F: add or remove items from the current display.

O or O: change the order in which items are displayed.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

The above is how to use the top command in linux to analyze system performance. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report