Monitoring system resource Usage under Linux system

Source: Internet
Author: User
Tags command line lowercase memory usage time interval cpu usage
How to monitor this system resource under the Linux operating system.


How do I monitor system resources?


in the Windows operating system, you can query the ratio of CPU to memory consumed by each process through Task Manager. There is no such graphical management in the Linux operating system. In command line mode, type the top command to see the system resources that each process occupies.


PPP


as a qualified system administrator, for system performance optimization or other considerations, often need to master the system in the most CPU or memory resources of the program. For this purpose, the system administrator needs to use the top command provided by the system. This command can help administrators monitor system resource usage, including memory, CPU, swap file partition usage, and so on. Is the result of the execution of this command. System administrators want to improve the performance of the operating system, the first step is to read the above table. If the content system administrator in this diagram is not able to understand, then he wants to improve the performance of the system simply can not start.


The results of the top command can be roughly divided into two parts. The top half is the information that makes some statistics, including the usage of memory and swap partitions, the operation of the CPU, the total number of processes, and so on. In these statistics, the system administrator should pay attention to the state of the process running in addition to the use of these important resources. It can be seen that there are four kinds of processes in the Linux system, namely running, sleeping, stopped and zombie. If you consider system maintenance and performance tuning, your system administrator needs to focus on those processes that are state-zombie. If the process is in this state, it is called a zombie process in the Linux operating system. What is a zombie process? The process by which the parent process is not dead, but the child process is dead. In Linux operating systems, processes are generally divided into parent processes and child processes. A process a may call another process B. At this point, the process A is called the parent process, and process B is called a child process. Due to some unexpected circumstances, the child process has stopped running, but the parent process has not yet known that the child process has already stopped running, and is there innocently waiting for the child process to return the results of the run. Because the child process does not return a result, the parent process may be waiting there all the time. Which leads to the degradation of system performance. If a system administrator discovers a zombie process, the first thing to do is to end the parent process (and sometimes to see the other child processes open by the parent process) to free up the system resources it occupies. Second, if this happens more frequently, the system administrator needs to analyze what causes this to happen. Take positive measures when you find the cause. Typically, if the child process's state is zombie, the parent process does not end automatically, and the system resources it occupies are not automatically freed, thereby reducing the performance of the operating system.


second, the top command of the use of skills.


1, select the appropriate sort order.


In the Windows operating system Task Manager, administrators can select the appropriate sort order, such as by CPU or by memory usage. In the display result of the top command, the CPU usage is sorted by default. What if the system administrator wants to sort by memory usage now? If you want to change the sort order of the top command results, you can press the M key to sort by memory. Note that the m here is lowercase, not uppercase. Most commands and parameter capitalization are sensitive in Linux operating systems. This is different from the DOS command in Microsoft's operating system. DOS commands are case-insensitive. Although this sort is not as convenient as the task Manager in Microsoft's operating system, sorting can be done with just 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 everyone thinks.


2, monitor the resources used by specific users.


In the Windows operating system, the operation is simple if you want to see which processes are open for a particular account and which system resources are consumed. You only need to open System Task Manager and then sort by user. You can tell which processes a user has started and what proportion they are occupying. In the top command, you do not have the ability to sort by account. That is, in the above display, you can sort only by memory usage or CPU load, not by user. In the same result, the process that was opened by the system privileged user root and the normal user was mixed. This is very inconvenient for the system administrator to find the cause of the problem. Sometimes a system administrator needs to view only the processes of a particular user, such as only the processes open by an Oracle account and the system resources that are consumed. and ignore the system account. Because other users of the privileged account do not have permission to log on, they are often running a system-level process that generally does not cause problems. And ordinary users can run some applications. Sometimes they get confused. May open some illegal programs, occupy a lot of system resources, thereby reducing system performance. Cut the crap, how can you look at the process that a particular account started? It's actually very simple. Now run the top command to let the system count the processes for all accounts. Then, when you need to view the process for a particular account, just press the U key (Note lowercase), and then enter the user name. At this point the system will automatically filter the process of other accounts to facilitate the system administrator to view. After filtering by the user, you can still press the M key to filter the actual results. If you need to look at a particular user's process in the first place, just add the-u option immediately after the top command and then bring the user name with you. However, if you want to view all users at this point, you can view all users ' processes with the top command and then the top command with no options. Alternatively, enter the character U in this window and press enter directly, or you can display process information for the user you are using.


3, dynamic statistic information.


Using the top command to count the running information of the process, like the Microsoft operating system's task Manager, is dynamically tuned. That is, the system will count the information every once in a while and then dynamically display it in the window. Users are not required to manually update the relevant information. And as you can see from the graph above, the top command counts more information than the Microsoft Task Manager statistics. Therefore, for the system administrator, has a greater reference value. I used to like the Microsoft operating system Task Manager. When you know the top command, you have added a fondness for it. Because it can not only complete all the features in Task Manager. And some of the information in the top command is not displayed in Microsoft Task Manager. And these information often to our maintenance system, enhance the performance has the very big reference value.


4, delete the process with exception. (material)


If this window finds that some of the processes are abnormal or that the user executes a specified application, such as consuming too much system resources or the presence of a zombie process, you can simply tell the deletion in this window. The way to do this is simply to enter the character p in the window, and the system administrator is prompted to enter the PID to turn off the process. The administrator only needs to type this value and then press ENTER to kill the unwanted process. However, when the process is closed, there are restrictions on permissions. System privileged account root can shut down processes for all users. A normal account can only delete a program that you open, but not the other user's process. If the system administrator logs on with an Oracle user first and discovers a process exception under the root account, you will be prompted for an error message that cannot be closed when you want to close it. At this point the administrator must terminate the top process and then use the SU command to change the login account. And then close the exception process. System administrators can close multiple processes at the same time. The simple approach is to enter several process numbers that need to be closed at the same time. Separated by commas is required between the individual process numbers.


Top is a useful command in system maintenance. In addition to implementing functions such as the above, you can set the time interval for their dynamic updates, and so on. It's important to note, however, that there is a slight difference in functionality in different versions of the Linux system, and that the layout and content of the display are different. For this reason, when your system administrator maintains a version that is not familiar to you, you sometimes need to review the help instructions for the system. You can get help by adding a number to the top command at this point. This online help document, like the top command, is a good helper for your system administrator. Unfortunately, these online help documents are now in English. So this is a very high requirement for the system administrator's English instructions.





Related Article

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.