Linux operating system analysis commands

PS command: mainly used to get some information about a process
-A: show all processes
-a: show all processes in a terminal, except for session leads
-N: ignore options
-d: show all processes, but omit all Session lead
-e: When listing programs, display the environment variables used by each program lock
-x: Display processes that do not have a controlling terminal, and display the specific paths of each command, dx cannot be used together
-p: pid: The time that the process uses the cpu
-u uid or username: select a valid user id or username
-g gid or groupname: show all processes in the group
-f: list all, usually used in conjunction with other options
-l: long format
-j: job
format- e: show the environment after the command
ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.2  47812 10092 ?        Ss   May10   2:09 /usr/lib/system
root         2  0.0  0.0      0     0 ?        S    May10   0:02 [kthreadd]
[root@iZ25op9f9tsZ ~]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 May10 ?        00:02:09 /usr/lib/systemd/systemd --system --deserialize 20
root         2     0  0 May10 ?        00:00:02 [kthreadd]
root         3     2  0 May10 ?        00:01:00 [ksoftirqd/0]

When you need to terminate, use the kill pid

TOP command: it is the most commonly used performance analysis tool under the Linux operating system, which can display the resources consumed by each process in the operating system in real time.
[root@iZ25op9f9tsZ ~]# top
top - 15:02:01 up 121 days,  3:44,  4 users,  load average: 0.00, 0.01, 0.05
Tasks:  88 total,   1 running,  87 sleeping,   0 stopped,   0 zombie
%Cpu (s): 0.5 us, 0.2 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem:   3883400 total,  3503288 used,   380112 free,   211088 buffers
KiB Swap:        0 total,        0 used,        0 free.  2275844 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                    
21186 root      20   0  164068  37020   5700 S   0.7  1.0 198:36.16 AliHids                                                                                                                    
   12 root      20   0       0      0      0 S   0.3  0.0  73:03.61 rcuos/0                                                                                                                    
   13 root      20   0       0      0      0 S   0.3  0.0  76:54.38 rcuos/1        

vmstat command:
vmstat 2 1
vmstat 2

This means that vmstat collects data every 2 seconds, and keeps collecting until I end the program. After collecting data 5 times, I end the program.

Well, the introduction of the command is completed, and now we will start to explain the meaning of each parameter in practice.

r represents the running queue (that is, how many processes are actually allocated to the CPU). The server I tested is currently relatively idle, and no programs are running. When this value exceeds the number of CPUs, there will be a CPU bottleneck. This is also related to the load of top. Generally, if the load exceeds 3, it is relatively high, if it exceeds 5, it is high, and if it exceeds 10, it is not normal, and the state of the server is very dangerous. The load of top is similar to the run queue per second. If the run queue is too large, it means that your CPU is very busy, which generally results in high CPU usage.

b means a blocked process, this is not much to say, the process is blocked, everyone understands.

The used size of swpd virtual memory. If it is greater than 0, it means that your machine's physical memory is insufficient. If it is not the cause of program memory leakage, then you should upgrade memory or migrate memory-consuming tasks to other machines.

The size of free physical memory, my machine has a total of 8G memory, and the remaining 3415M.

buff Linux/Unix system is used to store, what content in the directory, permissions, etc. cache, my local machine occupies about 300 M

cache cache directly used to memorize the files we open, buffer the files, my machine probably occupies More than 300 M (here is the cleverness of Linux/Unix. Part of the free physical memory is used to cache files and directories to improve the performance of program execution. When the program uses memory, buffer/cached will be very fast. is used.)

si The size of the virtual memory read from the disk per second. If this value is greater than 0, it means that the physical memory is not enough or the memory is leaked. Find the memory-consuming process and solve it. I have plenty of memory on my machine and everything works fine.

so The size of virtual memory written to disk per second, if this value is greater than 0, the same as above.

The number of blocks received per second by the bi block device. The block device here refers to all disks and other block devices on the system. The default block size is 1024 bytes. There are no IO operations on my machine, so it is always 0, but I have been processing The machine that copies a large amount of data (2-3T) can reach 140000/s, the disk write speed is about 140M per

second, and the number of blocks sent by the block device per second. For example, when we read a file, bo must be greater than 0. Bi and bo are generally close to 0, otherwise IO is too frequent and needs to be adjusted.

in The number of CPU interrupts per second, including the time interrupt

cs The number of context switches per second, for example, when we call a system function, we need to perform context switching, thread switching, and process context switching. This value should be as small as possible, too large. Now, consider reducing the number of threads or processes. For example, in web servers such as apache and nginx, we generally perform performance tests with thousands or even tens of thousands of concurrent tests. The process of selecting a web server can be determined by the process or The peak value of the thread has been lowered, and the pressure measurement is performed until the cs reaches a relatively small value. The number of processes and threads is a more appropriate value. The same is true of system calls. Every time a system function is called, our code will enter the kernel space, resulting in context switching. This is very resource-intensive, and we should try to avoid calling system functions frequently. Too many context switches means that most of your CPU is wasted in context switching, resulting in less time for the CPU to do serious work, and the CPU is not fully utilized, which is not desirable.

us User CPU time, I used to be on a server that performs frequent encryption and decryption, and I can see that us is close to 100, and the running queue of r reaches 80 (the machine is under stress test, and its performance is not good).

sy System CPU time, if it is too high, it means that the system call time is long, such as frequent IO operations.

id is the idle CPU time. Generally speaking, id + us + sy = 100. Generally, I think id is the idle CPU usage, us is the user CPU usage, and sy is the system CPU usage.

wt wait for IO CPU time.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326499819&siteId=291194637