Although the Linux operating system is much more stable than the Windows operating system. However, this stability is relative. That is to say, the Linux operating system may also get angry. In some cases, the system's resource usage (including CPU or memory) may reach more than 90%. To this end, the system administrator still needs to monitor the usage of system resources when necessary. Today, I will introduce how to monitor system resources in Linux.
1. How to monitor system resources?
In Windows, you can use the task manager to query the CPU-to-memory ratio of each process. This graphical management is not available in Linux. In command line mode, type the top command to view the system resources occupied by each process. As shown in:
Ppp
As a qualified system administrator, for system performance optimization or other considerations, you often need to master the programs that consume the most CPU or memory resources in the system. To achieve this goal, the system administrator needs to use the top Command provided by the system. This command helps administrators monitor the usage of system resources, including memory, CPU, and swap file partition usage. As shown in, it is the execution result of this command. To improve the performance of the operating system, the system administrator must read the table above. If the content system administrator in this figure cannot understand it, then he wants to improve the system performance.
The running result of the Top command can be roughly divided into two parts. The upper half is to make some statistical information, including memory and swap partition usage, CPU running, the total number of processes, and so on. In these statistics, the system administrator should pay attention to the usage of these important resources and the running status of processes. As shown in, there are four main processes in Linux: running, sleeping, stopped, and zombie. If you consider system maintenance and performance optimization, the system administrator needs to focus on processes in zombie state. If the process is in this state, it is called a zombie process in the Linux operating system. What is a zombie process? That is, the processes where the parent process is not dead but the child process is dead. In Linux, processes are generally divided into Parent and Child processes. A process A may call another process B. In this case, process A is called the parent process, and process B is called the child process. Due to some unexpected situations, the sub-process has stopped running, but the parent process does not know that the sub-process has stopped running, and is still waiting for the sub-process to return the running result. Because the child process does not return results, the parent process may wait there. This results in a reduction in system performance. If the system administrator finds a zombie process, the first thing to do is to end the parent process (sometimes you need to check the running status of other sub-processes opened by the parent process ), to release the system resources it occupies. Second, if this happens frequently, the system administrator needs to analyze the cause of this situation. Take positive measures after finding the cause. Generally, if the sub-process is in the "zombie" state, the parent process will not end automatically, so that the system resources it occupies will not be automatically released, thus reducing the operating system performance.
Ii. Tips for using Top commands.
1. select an appropriate sorting order.
In the job manager of a Windows operating system, the administrator can select an appropriate sorting order as needed, such as sorting by CPU or by memory usage. The display result of the top command is sorted by CPU usage by default. What should I do if the system administrator wants to sort by memory usage? If you want to change the sorting order of the top command results, you can sort the results by memory by the m key. Note that m is in lower case, not in upper case. In Linux, most commands and parameters are case sensitive. This is different from the DOS command in Microsoft operating system. The doscommand is case-insensitive. Although this sorting is not as convenient as the task manager in the Microsoft operating system, you only need to click to complete the sorting. However, as long as you are familiar with related commands, it is not as difficult as you think about sorting them in the command line.
2. Monitor resources used by specific users.
In Windows, if you want to view the processes opened by a specific account and the system resources consumed, the operation is very simple. You only need to open the system task manager and sort by user. You can know the processes started by a user and the proportion occupied by them. The top command does not support sorting by account. That is, in the above display result, you can only sort by memory usage or CPU load, but not by user. As shown in, the process opened by the system privileged user root and common user is mixed in the same result. This is inconvenient for the system administrator to find the cause of the problem. Sometimes the system administrator only needs to view the processes of a specific user, such as the processes opened by the oracle account and the system resources occupied. The system account is ignored. Other users of the privileged account do not have the right to log on, and they usually run system-level processes. Common users can run some applications. Sometimes they are confused and may open some illegal programs, occupying a large amount of system resources, thus reducing system performance. How can I view the processes started by a specific account? It is actually very simple. Run the top command to let the system count the processes of all accounts. Then, when you want to view the process of a specific account, you only need to press the u key (note the lower case), and then enter the user name. At this time, the system will automatically filter out the processes of other accounts 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 specific user at the beginning, you only need to add the-u option directly after the top command and then add the specific user name. However, if you want to view all the users again, you must first launch the top command and then use the top command without any options to view the processes of all users. In other words, enter the u character in this window and press the Enter key to display the process information of the user.
[NextPage]
3. Dynamic statistics.
The top command is used to calculate the running information of processes. It is dynamically adjusted like the task manager of the Microsoft operating system. That is to say, the system will calculate this information at intervals and dynamically display it in the window. You do not need to manually update related information. As shown in the figure above, the top command statistics are much more than the Microsoft Task Manager statistics. Therefore, it has greater reference value for system administrators. I used to like to use Microsoft's task manager. After learning about the top command, I love it. It not only completes all functions in the task manager. In addition, some information in the top command cannot be displayed in the Microsoft task manager. This information is often of great reference value for us to maintain the system and improve performance.
4. Delete abnormal processes.
In this window, if you find that some processes are abnormal or applications other than the user executes the regulations, such as occupying too much system resources or zombie processes, you can delete it directly in this window. The operation method is very simple. You only need to enter the p character in this window, and then the system will prompt the system administrator to enter the PID of the process to be disabled. The Administrator only needs to enter this value, and then press the Enter key to Kill unnecessary processes. However, when you close a process, you have permission restrictions. The system privileged account root can shut down all user processes. A normal account can only delete programs opened by itself, but cannot close processes of other users. For example, if the system administrator logs on as an oracle user and finds that a process under the root account is abnormal, the system will prompt an error message indicating that the process cannot be closed. In this case, the Administrator must terminate the top process and then use the su command to change the account to log on. Then shut down the abnormal process. The system administrator can shut down multiple processes at the same time. The method is simple, that is, enter multiple process numbers to be disabled at the same time. Process numbers must be separated by commas.
Top is a useful command in system maintenance. In addition to the above functions, you can also set the time interval for dynamic updates. However, the functions of Linux systems of different versions are slightly different, and their display layout and content are also different. For this reason, when the system administrator maintains a version that is not very familiar with, sometimes you need to view the help instructions of the system. In this case, you only need to add? To get help. The root top command of this online help document is the same as that of the system administrator. Unfortunately, these online help documents are all in English. Therefore, the requirements for system administrators are high in English.