Linux monitoring system resource usage rate

  
Although the Linux operating system is much more stable than the Windows operating system. But this stability is relatively speaking. In other words, the Linux operating system will also have a temper. In some cases, the system's resource usage (including CPU or memory) will reach more than 90% or more. For this reason, system administrators still need to monitor the use of system resources when necessary. The author will introduce to you today, how to monitor this system resources under the Linux operating system, to be aware of it.
First, how to monitor system resources?
In the Windows operating system, you can use the task manager to query the ratio of CPU to memory occupied by each process. There is no such graphical management in the Linux operating system. In the command line mode, type the top command to see the system resources occupied by each process.
ppp
As a qualified system administrator, for system performance optimization or other considerations, it is often necessary to master the most CPU or memory resources in the system. In order to achieve this, the system administrator needs to use the top command provided by the system. This command helps administrators monitor system resource usage, including memory, CPU, swap file partition usage, and more. This is the result of the execution of this command. The first step for system administrators to improve the performance of the operating system is to read the above table. If the content system administrator in this picture can't understand it, then he wants to improve the performance of the system.
The results of the Top command can be roughly divided into two parts. The top half is to make some statistical information, including the use of memory and swap partitions, the operation of the CPU, the total number of processes, and so on. In these statistics, in addition to paying attention to the use of these important resources, system administrators need to pay attention to the state of the process running. It can be seen that there are four main states of the process in the Linux system, namely running, sleeping, stopped and zombie. If you consider system maintenance and performance optimization, system administrators need to pay attention to processes whose status is zombie. If the process is in this state, it is called a zombie process in the Linux operating system. What is a zombie process? It is a process in which the parent process has not died, but the child process has died. In the Linux operating system, processes are generally divided into parent processes and child processes. A process A may call another process B. At this point, process A is called the parent process, and process B is called the child process. Due to some unexpected circumstances, the child process has stopped running, but the parent process does not know that the child process has stopped running, and still waits for the child process to return the running result. Since the child process does not return a result, the parent process may always wait there. This leads to a decline in system performance. If the system administrator finds that there is a zombie process, the first thing to do is to end the parent process (sometimes also need to see the other child processes running by the parent process) to release the system resources it occupies. Secondly, if this happens more frequently, the system administrator needs to analyze what is causing the situation. Take positive steps after finding the cause. Normally, if the state of the child process is "zombie", the parent process will not automatically end, so the system resources it occupies will not be automatically released, thus reducing the performance of the operating system.
Second, the use of Top commands.
1. Select the appropriate sort order.
In the task manager of the Windows operating system, the administrator can select the appropriate sort order according to the needs, such as sorting by CPU or sorting by memory usage. In the display result of the top command, the default is to sort according to the CPU usage rate. If the system administrator wants to sort by memory usage, what should I do? If you want to change the sort order of the top command results, you can press m to sort by memory. Note that m here is lowercase, not uppercase. Most commands and parameter cases are sensitive in the Linux operating system. This is different from the DOS commands in the Microsoft operating system. The Dos command is not case sensitive. Although this sorting is not as convenient as the task manager in the Microsoft operating system, you can complete the sorting with a click of the mouse. But as long as you are familiar with the relevant commands, sorting them on the command line is not as difficult as you think.
2. Monitor the resources used by specific users.
In the Windows operating system, if you want to view the processes opened by a particular account and the system resources used, the operation is very simple. Just open the System Task Manager and sort by user. You can know which processes are open to a user and the percentage they are using. In the top command, there is no function to sort by account. That is to say, in the above display result, the sorting can only be performed according to the memory usage rate or the CPU load, and the sorting cannot be performed by the user. In the same result, the system privileged user root and the process opened by the normal user are mixed. This is very inconvenient for the system administrator to find the cause of the problem. Sometimes system administrators often need to view only the processes of specific users, such as only the processes opened by the oracle account and the system resources occupied. Ignore the system account. Because other users of the privileged account do not have the right to log in, and they often run some system-level processes, there is generally no problem for this. Ordinary users can run some applications. Sometimes they are confused and may open up some illegal programs, taking up a lot of system resources, thus reducing system performance. Less nonsense, how can I view the processes started by a particular account? It's actually very simple. Now run the top command to let the system count the progress of all accounts. Then, in the process that needs to view the specific account, just press u (note lowercase) and enter the username. At this point, the system will automatically filter out the processes of other accounts, which is convenient for the system administrator to view. After filtering by user, you can still press the m key to filter the actual results. If you need to view the process of a particular user at the beginning, you only need to add the -u option directly after the top command and bring the specific username. However, if you want to view all users at this time, you only need to launch the top command first, and then use the top command without any options to view the progress of all users. Or, enter the character u in this window, and then press the Enter key directly to display the progress information of the user used.
Copyright © Windows knowledge All Rights Reserved