Monitor the usage of Linux System Resources (1)

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.