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 in Linux

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

Share

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

This article will explain in detail how to use the top command in Linux, Xiaobian feels quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

I. Introduction

Top command diagram:

*** Line-Basic information

load average:

Load average represents the average load of the system. Use top or uptime to view the information of load average. Three numerical values represent the average load of the system within 1 minute, 5 minutes and 15 minutes. To understand the meaning of these three numerical values, you must first understand the "kernel number" of the system.

Number of cores of the system = CPU1 x Number of cores of CPU1 + CPU2 x Number of cores of CPU2 + CPU n x Number of cores of CPU n+ …

To be clear, type grep -c 'model name' /proc/cpuinfo on Linux to get the kernel.

Back to the load average, the saturation value of the load average is equal to the number of cores of the system, so, according to the load average to observe the system load first depends on the number of "cores" in the system, the saturation value of a single processor single core is 1, the saturation value of a single processor dual core is 2, and the saturation value of a dual processor single core is also 2.

The classic example of understanding load averaging is to think of a CPU core as a one-way bridge. As shown in the figure:

Assuming that the system is currently a single-core system, its load saturation value is 1 according to the above description. Under these conditions, the values mean:

0.00 It means there's no traffic on the bridge. It's very clear.

0.50 It means that the traffic flow on the bridge with half of the capacity is also relatively smooth.

1.00 It means that the bridge has reached the *** carrying capacity. If there is another car coming, it may have to wait a little before it can get on the bridge. In this case, the speed will be very slow, which will often cause the average load to continue to rise.

1.70 It means that the bridge has reached *** load, and there are 70% vehicles waiting to get on the bridge relative to *** load of the bridge. At this time, the system is already overwhelmed.

In practical applications, focus on the average load of 5 minutes and 15 minutes. When it reaches 0.7, it is necessary to investigate the cause.

2. task information

Zombie Process: Indicates a process that has terminated but still retains some information. It waits for the parent process to call wait() and can be completely removed from memory. Will be processes that cannot be cleaned using kill. If you want to manually clean up a zombie process, you need to find its parent process. After killing the parent process, the init process of LInux will take over the zombie process (all child processes in linux need to have a parent process. When the parent process is killed, all its child processes will be passed on to the init process). The init process calls wait() every once in a while to clean up the zombie process.

3. CPU usage

4. Physical memory usage

buff/cache:

Buffers and cache are data stored in memory, the difference is that buffers store data to be written to disk, while cache stores data read from disk.

On Linux, there is a daemon that periodically writes data from buffers to disk, or manually writes data from buffers to disk using the sync command. Buffers can be used to centralize scattered I/O operations, reducing disk seek time and disk fragmentation.

Cache is Linux to read high frequency data, put into memory, reduce I/O. Cache in Linux does not have a fixed size, and is automatically added or deleted according to usage.

#Manually write buffers to hard drive and empty cachesync && echo 3 > /proc/sys/vm/drop_caches

5. Exchange Area Usage

Swap(memory swap area):

It's a space on the hard drive. In the case of insufficient memory, the operating system stores unused data in memory into the swap area of the hard disk, freeing up memory for other programs to run. Therefore, opening swap will cause I/O performance to decline to a certain extent (Ali server does not open by default).

6. process details

Second, flexible use of top

1. command-line usage

-b: operate in batch mode this way you can write top output to a file top -b >> top.txt in readable form

-c: Display the complete command line (COMMAND), useful when you want to see where the process is executing

-d: Screen refresh interval time top -d 1: Refreshes every second

-s: Use privacy mode

-S: Specify cumulative mode

-i: Do not show any idle or dead processes

-u: Specify username

-p: Specify the process

-n: Specify the number of times the loop is displayed, and exit by itself.

2. interactive use

The top command displays the real-time status of the system and supports interactive operations. Execute the top command to display the system status interface (which is also an interactive interface). Enter the interactive command:

1: View CPU usage per core

h: Display a help screen that gives a brief summary of the command

k: Terminate a process

i: Ignore idle and dead processes, this is a switch command

q: exit procedure

r: Rearrange the priority of a process

S: Switch to accumulation mode

s: Change the delay time between two refreshes (in s), converted to ms if there are decimals. Enter a value of 0 and the system will refresh continuously. The default value is 5s.

l: Switch to display average load and start-up time information

m: Switch display memory information

t: Switch display process and CPU status information

c: Toggle display command name and full command line

M: Sort by resident memory size

P: Sort by CPU usage percentage size

T: Sort by time/cumulative time

w: Writes the current settings to the ~/.toprc file.

About "how to use the top command in Linux" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

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