Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to monitor system resource utilization by Linux

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how Linux monitors system resource utilization", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "Linux how to monitor system resource utilization"!

Linux operating system is more stable than Windows operating system. But stability is relative. In other words, Linux operating systems can have tantrums. In some cases, the resource utilization rate of the system (including CPU or memory) will reach more than 90% or even more. For this reason, system administrators still need to monitor the use of system resources when necessary. Today, I will introduce to you how to monitor this system resource under the Linux operating system and know it.

How do I monitor system resources?

In Windows operating systems, you can query the CPU to memory ratio of each process through Task Manager. There is no such graphical management in Linux operating systems. In 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 consuming programs in the system. To do 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 so on. is the result of this command. The first step for system administrators who want to improve the performance of their operating systems is to read the table above. If the system administrator can't understand the contents of this kind of diagram, then he wants to improve the performance of the system and can't start.

The results of running the Top command can be roughly divided into two parts. The top half is statistical information, including memory and swap partition usage, CPU health, total number of processes, and so on. Among these statistics, system administrators need to pay attention to the state of process operation in addition to the use filter of these important resources. There are four main states of processes in Linux: running, sleeping, stopped, and zombie. For system maintenance and performance optimization purposes, system administrators need to focus on processes with zombie status. If the process is in this state, it is called a zombie process in the Linux operating system. What is a zombie process? Those processes where 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. One process A may call another process B. Process A is called the parent process and process B is called the child process. Due to some unexpected situation, the child process has stopped running, but the parent process does not know that the child process has already stopped running, and is still waiting for the child process to return the running result. Since the child process does not return results, the parent process may be waiting there. This leads to a decrease in system performance. If the system administrator finds a zombie process, the first thing to do is to end the parent process (and sometimes check the other child processes opened by the parent process) to free up the system resources it is consuming. Second, if this happens more frequently, the system administrator needs to analyze what is causing this to happen. After finding the cause, take positive measures. Usually, if the child process is in a zombie state, the parent process will not automatically terminate, so that the system resources it occupies will not be automatically released, thus reducing the performance of the operating system.

Second, the use of the Top command skills.

1. Select the appropriate sorting order.

In Task Manager for Windows operating systems, administrators can choose the appropriate sort order as needed, such as sorting by CPU or sorting by memory usage. By default, the top command displays results sorted by CPU usage. What if the system administrator now wanted to sort by memory usage? If you want to change the sort order of the top command results, press m to sort by memory. Note that m is lowercase, not capital. Most commands and arguments in Linux are case-sensitive. This is different from DOS commands in Microsoft operating systems. The Dos command is case insensitive. Although this sort is not as convenient as the task manager in Microsoft OS, it can be done with just a click of the mouse. But as long as you're familiar with the commands, sorting them on the command line isn't as difficult as you might think.

2. Monitor the resources used by specific users.

On Windows, it's easy to see what processes are open and what system resources are consumed by a particular account. Just open the System Task Manager and sort by user. You can know which processes a user has opened and what percentage they occupy. In the top command, there is no ability to sort by account. That is, in the above display results, you can only sort by memory usage or CPU load, but not by user. In the same result, there are processes opened by the system privileged user root and the normal user. This is very inconvenient for system administrators to find the cause of the problem. Sometimes system administrators often need to view only the processes of a particular user, such as only the processes opened by the oracle account and the system resources consumed. Ignore the system account. Because other users of privileged accounts do not have the right to log in, and they often run some system-level processes, there is generally no problem. And ordinary users can run some applications. Sometimes they muddle through and may open illegal programs that take up a lot of system resources and slow down system performance. Cut the crap, how can I view the processes started by a particular account? It's actually quite simple. Now run the top command to have the system count all accounts 'progress. Then in the process of viewing a specific account, just press the u key (note lowercase) and enter the username. At this point, the system will automatically filter out the processes of other accounts for the convenience of system administrators. After pressing user filter, you can still press m to filter the actual results. If you want to see a particular user's progress at the beginning, you can simply add the-u option directly after the top command with the specific user name. However, if you want to see all users at this point, you can only launch the top command first, and then use the top command without any options to see all users 'progress. Alternatively, enter the character u in this window and press Enter directly to display the user's progress information.

3. Dynamic statistical information.

Use the top command to count the running information of the process, just like the task manager of the Microsoft operating system, which is dynamically adjusted. That is to say, the system will count this information every once in a while, and then dynamically display it in the window. Users do not need to manually update relevant information. And as you can see from the graph above, the top command counts more information than Microsoft Task Manager counts. Therefore, for system administrators, it has greater reference value. I used to love Microsoft's Task Manager. After learning about the top command, I loved it. Because it can not only complete all the functions in the task manager. And some of the information in the top command is not displayed in Microsoft Task Manager. And these information often have great reference value for us to maintain the system and improve its performance.

4. Delete abnormal processes.

If in this window, some processes are found to be abnormal or the user executes an application other than the specified one, such as taking up too many system resources or the existence of zombie processes, you can delete them directly in this window. The method of operation is very simple, just need to enter the character p in this window, and then the system administrator will be prompted to enter the PID to close the process. Administrators simply type in this value and press Enter to kill unwanted processes. However, when closing a process, there are permission restrictions. The system privileged account root can shut down all user processes. Normal accounts can only delete programs they open, and cannot close other users 'processes. For example, if the system administrator logs in as oracle user first, and finds that a process under the root account is abnormal, and wants to close it, the system will prompt an error message that cannot be closed. At this point the administrator must terminate the top process and then change the login account using the su command. Then close the exception process. System administrators can shut down multiple processes simultaneously. The method is very simple, that is, enter multiple process numbers to be closed at the same time. Commas are used to separate process numbers.

top is a very useful command in system maintenance. In addition to the above functions, you can also set the time interval for its dynamic update, etc. However, it should be noted that its functions vary slightly between different versions of Linux systems, and its layout and content are also different. For this reason, when system administrators maintain versions they are not familiar with, it is sometimes necessary to check the system's help description. You just need to add the top command. You can get relevant help. This online help document, like the top command, is a great helper for system administrators. Unfortunately, these online help documents are now in English. Therefore, this system administrator's English description requirements are relatively high.

At this point, I believe that everyone has a deeper understanding of "how Linux monitors system resource utilization", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report