How to check CPU usage in Linux system!

  Linux is an open source operating system, which is also widely used in servers and embedded devices. As a server operating system, it is very important to monitor the usage of system resources, so how to check the CPU usage on the Linux system? ?The following are the details:

  1. Use the top command

  The top command is a commonly used Linux system monitoring command, which can view the process and resource usage of the system in real time. You can use the following command to view CPU usage:

  top

  After starting the top command, it will display the resource usage of the current system, including the CPU usage. On the top interface, you can see a CPU line, which contains information about the CPU usage. For example:

  %Cpu(s): 5.0 us, 2.0 sy, 0.0 ni, 93.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st

  Among them, us represents the CPU utilization rate of the user space program, sy represents the CPU utilization rate of the system kernel, and id represents the idle time of the CPU.

  2. Use the mpstat command

  The mpstat command is a Linux system monitoring command that can display CPU usage and other CPU statistics in real time. The mpstat command displays the usage of all CPUs by default. You can use the following command to view the CPU usage:

  mpstat

  After starting the mpstat command, it will display the usage of each CPU core, including user space programs, system kernel, idle and other related information. For example:

  02:40:01 AM CPU %user %nice %sys %iowait %irq %soft %steal %guest %idle

  02:40:01 AM all 5.42 0.02 2.09 0.04 0.00 0.01 0.00 0.00 92.42

  Among them, %user represents the CPU usage of user space programs, %sys represents the CPU usage of the system kernel, and %idle represents the idle time of the CPU.

  3. Use the sar command

  The sar command is a Linux system monitoring command that can view CPU usage and other system performance indicators in real time. The sar command requires the sysstat toolkit to be installed. You can use the following command to view CPU usage:

  became -u

  After starting the sar command, it will display the CPU usage, including user space programs, system kernel, idle and other related information. For example:

  12:00:01 AM CPU %user %nice %system %iowait %steal %idle

  12:10:01 AM all 8.24 0.00 3.29 0.02 0.00 88.45

  Among them, %user indicates the CPU usage of user space programs, %system indicates the CPU usage of the system kernel, and %idle indicates the idle time of the CPU.

  In addition to the above commands, you can also use other tools to view the CPU usage, such as htop, nmon, etc. These tools provide a richer interface and functionality to display system resource usage in more detail.

  Summarize

  You can use commands such as top, mpstat, and sar to view the CPU usage on a Linux system, and you can also use some other tools. Select an appropriate command or tool for monitoring based on actual needs. By checking the CPU usage in real time, you can keep abreast of the running status of the system and make corresponding optimizations and adjustments.

Guess you like

Origin blog.csdn.net/oldboyedu1/article/details/132341739