Detailed explanation of Linux heavy use commands (top, uptime, ps, netstat commands)

preface:

Seeing the title of this article, many small partners may feel strange. What is heavy? Severe here means commands that are used very frequently in Linux system, that is, some commands that will be used very frequently in daily operation and maintenance work.

Of course, there are many commonly used commands. Although they are relatively simple commands, they are very useful and need to pay attention to many details, and can be classified. For example, the four commands to be explained in this article are commands to quickly view the system status. It is not easy to use these heavy commands well, If you don't believe it, just look down ~ ~ ~ ~!!!!!

1, top command

The use scenario of the top command is generally operation and maintenance patrol and when the system is abnormally stuck, it is necessary to quickly obtain the status of the CPU, memory and main processes of the overall system through this command   Whether the system operates healthily, or quickly locate the abnormal causes, so as to accurately give the scheme to adjust the system operation.

Because the output of the top command is about the process, the command is deeply bound with the ps command. In daily use, it is usually used together with the ps command.

The top command has no authority and can be used by ordinary users or root users. Therefore, this command is an important command, and many key information of the system can be obtained through this command.

(1) Help parsing of top command

The output of top --help is as follows:

[root@hdp-1 ~]# top --help
top: inappropriate '-help'
Usage:
  top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]

Of course, the top command is usually run without parameters, that is, directly top   Just throw it into the terminal. If you have to use parameters, - U - P   Parameters are more practical.

top -u   User equals top   U   User, only all processes of the specified user are displayed. For example, I display all processes run by my ordinary user ZSK. The command is   top   U   zsk     The output is as follows:

top - 01:34:05 up  1:11,  2 users,  load average: 0.01, 0.02, 0.02
Tasks: 184 total,   1 running, 183 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  8173312 total,  7845164 free,   199656 used,   128492 buff/cache
KiB Swap:  4718588 total,  4718588 free,        0 used.  7767732 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                
 1870 zsk       20   0  115448   2060   1652 S   0.0  0.0   0:00.01 bash                                                                                                   
 1912 zsk       20   0  162016   2328   1584 R   0.0  0.0   0:00.01 top

top -p 1   Display the system daemon. For example, if I query that my PHP fpmpid is 1414, then top -p 1414, the output is as follows:

top - 01:33:09 up  1:10,  2 users,  load average: 0.03, 0.03, 0.02
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  8173312 total,  7845560 free,   199260 used,   128492 buff/cache
KiB Swap:  4718588 total,  4718588 free,        0 used.  7768128 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                
    1 root      20   0  191024   4020   2584 S   0.0  0.0   0:01.39 systemd  





top - 01:29:59 up  1:07,  2 users,  load average: 0.00, 0.01, 0.02
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  8173312 total,  7845764 free,   199056 used,   128492 buff/cache
KiB Swap:  4718588 total,  4718588 free,        0 used.  7768332 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                
 1414 apache    20   0  405064   6748    800 S   0.0  0.1   0:00.00 php-fpm   

Unfinished to be continued~~~

Tags: Linux Operation & Maintenance Object Detection

Posted on Tue, 07 Sep 2021 13:48:14 -0400 by BrandonKahre