编程知识 cdmana.com

Dry goods recommendation: CentOS of computer knowledge

I don't know how others , I always use top This command , To check the occupancy of the system process . If you find that , Which process occupies the exception , Just deal with it .

 


 

Command specification

top The order is Linux Common performance analysis tools , It can display the resource usage of each process in the system in real time , Be similar to Windows Task manager .top Is a dynamic display process , That is to say, the current status can be refreshed continuously by pressing the button of the user .

If the command is executed in the foreground , It will have exclusive foreground , Until the user terminates the program . To be more precise ,top Command provides real-time status monitoring of system processors .

It will be displayed in the system CPU most “ sensitive ” Task list for . The command can be pressed CPU Use 、 Sort tasks by memory usage and execution time ; And many features of this command can be set through interactive command or in personal customization file .

Command format

top - Parameters

Command function

Displays information about the processes currently being executed by the system , Including process ID、 Memory usage 、CPU Occupancy rate, etc

Command parameter

Here are top Parameters that can be followed by the command , In general, I use -u that will do .

-b  It's batch processing

-c  yes   Show full command

-I yes Ignore failure process

-s yes   Confidentiality mode

-S  It's a cumulative pattern

-i  yes < Time > Set interval

-u yes < user name > Specify user name

-p  yes < Process number > Specify process

n yes < frequency > Number of cycles

Command demonstration

 


 

top

Direct input top, All process information will be displayed dynamically . then , Press the shift+> perhaps shift+< You can switch the sort mode , Default to cpu Occupancy order .

[root@210789 ~]# top

top - 23:41:42 up 25 days, 10:55,  1 user,  load average: 0.00, 0.00, 0.00

Tasks: 118 total,  2 running, 116 sleeping,  0 stopped,  0 zombie

%Cpu(s):  0.2 us,  0.2 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

MiB Mem :  3635.0 total,    295.2 free,  1605.4 used,  1734.4 buff/cache

MiB Swap:      0.0 total,      0.0 free,      0.0 used.  1740.3 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM    TIME+ COMMAND

336386 memcach+  20  0  442880  34300  1736 S  0.3  0.9  12:10.84 memcached

380953 root      10 -10  166012  33784  16232 S  0.3  0.9  77:41.24 AliYunDun

      1 root      20  0  179172  11116  8168 S  0.0  0.3  0:20.15 systemd

      2 root      20  0      0      0      0 S  0.0  0.0  0:00.44 kthreadd

      3 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 rcu_gp

      4 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 rcu_par_gp

      6 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 kworker/0:0H-kblockd

      8 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 mm_percpu_wq

      9 root      20  0      0      0      0 S  0.0  0.0  0:02.06 ksoftirqd/0

    10 root      20  0      0      0      0 I  0.0  0.0  2:42.80 rcu_sched

    11 root      rt  0      0      0      0 S  0.0  0.0  0:00.10 migration/0

    12 root      rt  0      0      0      0 S  0.0  0.0  0:00.02 watchdog/0

    13 root      20  0      0      0      0 S  0.0  0.0  0:00.00 cpuhp/0

    14 root      20  0      0      0      0 S  0.0  0.0  0:00.00 cpuhp/1

    15 root      rt  0      0      0      0 S  0.0  0.0  0:01.81 watchdog/1

    16 root      rt  0      0      0      0 S  0.0  0.0  0:00.10 migration/1

    17 root      20  0      0      0      0 S  0.0  0.0  0:01.80 ksoftirqd/1

    19 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 kworker/1:0H-kblockd

    21 root      20  0      0      0      0 S  0.0  0.0  0:00.00 kdevtmpfs

    22 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 netns

    23 root      20  0      0      0      0 S  0.0  0.0  0:00.10 kauditd

    26 root      20  0      0      0      0 S  0.0  0.0  0:00.98 khungtaskd

    27 root      20  0      0      0      0 S  0.0  0.0  0:00.00 oom_reaper

    28 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 writeback

    29 root      20  0      0      0      0 S  0.0  0.0  0:00.00 kcompactd0

    30 root      25  5      0      0      0 S  0.0  0.0  0:00.00 ksmd

    31 root      39  19      0      0      0 S  0.0  0.0  0:04.55 khugepaged

    32 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 crypto

    33 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 kintegrityd

    34 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 kblockd

    35 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 tpm_dev_wq

    36 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 md

    37 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 edac-poller

    38 root      rt  0      0      0      0 S  0.0  0.0  0:00.00 watchdogd

    60 root      20  0      0      0      0 S  0.0  0.0  0:00.36 kswapd0

    153 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 kthrotld

    154 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 acpi_thermal_pm

    155 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 kmpath_rdacd

    156 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 kaluad

    158 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 ipv6_addrconf

    159 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 kstrp

    413 root      0 -20      0      0      0 I  0.0  0.0  0:02.68 kworker/1:1H-xfs-log/vda1

    428 root      0 -20      0      0      0 I  0.0  0.0  0:00.00 ata_sff


 

top -u

Input top -u user, such as top -u apache Can be displayed apache Process information ; Input top -u mysql Can display database process information , The following example .

[root@210789 ~]# top -u apache

top - 23:43:34 up 25 days, 10:57,  1 user,  load average: 0.08, 0.05, 0.01

Tasks: 118 total,  1 running, 117 sleeping,  0 stopped,  0 zombie

%Cpu(s):  0.3 us,  0.2 sy,  0.0 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.2 si,  0.0 st

MiB Mem :  3635.0 total,    291.6 free,  1608.8 used,  1734.6 buff/cache

MiB Swap:      0.0 total,      0.0 free,      0.0 used.  1736.8 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM    TIME+ COMMAND

430740 apache    20  0 2312532 305912  49332 S  0.0  8.2  0:23.45 httpd

430741 apache    20  0 2305464 306720  49784 S  0.0  8.2  0:26.47 httpd

430742 apache    20  0 2297356 290864  48532 S  0.0  7.8  0:22.91 httpd

430940 apache    20  0 2252668 251372  47936 S  0.0  6.8  0:14.52 httpd

432551 apache    20  0 2175152 137612  45244 S  0.0  3.7  0:02.32 httpd

[root@210789 ~]# top -u mysql

top - 23:44:11 up 25 days, 10:58,  1 user,  load average: 0.04, 0.04, 0.01

Tasks: 117 total,  1 running, 115 sleeping,  1 stopped,  0 zombie

%Cpu(s):  0.8 us,  1.0 sy,  0.0 ni, 98.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

MiB Mem :  3635.0 total,    290.4 free,  1609.8 used,  1734.7 buff/cache

MiB Swap:      0.0 total,      0.0 free,      0.0 used.  1735.8 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM    TIME+ COMMAND

336344 mysql    20  0 2552992 309912  25192 S  0.0  8.3  10:33.91 mariadbd

Follow up instructions

These orders are usually enough , If you have more needs , Parameters can be changed , To view the . Except as mentioned in the article shift+< and shift+> Command switching top sort order , stay top In the command window , You can also use the following command for interactive operation . namely , stay top Under orders , Press the following key , You can do something about it .

 


 

h: Display help screen , Give 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: Re prioritize a process

S: Switch to cumulative mode

s: Change the delay time between refreshes ( Unit is s), If there are decimals , Just translate it into ms. Input 0 Value, the system will continue to refresh , The default value is 5s

f perhaps F: Add or remove items from the current display

o perhaps O: Change the order in which items are displayed

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

m: Toggle display memory information

t: Toggle display progress and CPU State information

c: Toggle display command name and full command line

M: Sort by resident memory size

P: according to CPU Sort by percentage size

T: According to time / Sort the cumulative time

W: Write current settings to ~/.toprc In file

If you are learning C/C++ There are some problems in the process , Make up a little circle of penguins ~ Xiaobian is very enthusiastic (●’◡’●)

版权声明
本文为[Tangerine]所创,转载请带上原文链接,感谢

Scroll to Top