Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to troubleshoot the problem of high CPU occupancy rate in Linux system

Shulou Source: shulou.com Published: 2022-06-01 11:08:28 09月19日 Update

This article introduces the relevant knowledge of "how to troubleshoot the problem of high CPU occupancy rate in Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Many OPS students are often at a loss when they encounter this situation. The following two methods are usually used to quickly locate the problem of CPU overload:

Method one

Step 1: use the

Top command, and then sort by shift+p by CPU

Find the pid of the process that consumes too much CPU

Step 2: use the

Top-H-p [process id]

Find the id of the thread in the process that consumes resources *

Step 3: use the

Echo 'obase=16; [thread id]' | bc or printf "% x\ n" [thread id]

Convert thread id to hexadecimal (lowercase letters)

Bc is the calculator command of linux

Step 4: execute

Jstack [process id] | grep-A 10 [hexadecimal of thread id] "

View thread status information

Method two

* step: use the

Top command, and then sort by shift+p by CPU

Find a process that takes up too much CPU

Step 2: use the

Ps-mp pid-o THREAD,tid,time | sort-rn

Get thread information and find the thread that takes up high CPU

Step 3: use the

Echo 'obase=16; [thread id]' | bc or printf "% x\ n" [thread id]

Convert the required thread ID to hexadecimal format

Step 4: use the

Jstack pid | grep tid-A 30 [hexadecimal of thread id]

Print the stack information for the thread

Case analysis

1. Scene description

Troubleshooting of JAVA process with High CPU occupancy in production Environment

two。 Solution process

(1) according to the top command, it is found that the Java process with a PID of 2633 takes up up to 300% of the CPU and fails.

(2) after finding the process, how to locate the specific thread or code? first, display the list of threads and sort them according to the threads with high CPU occupation:

[root@localhost ~] # ps-mp 2633-o THREAD,tid,time | sort-rn

The display results are as follows:

Found a time-consuming thread (TID) 3626, which took up 12 minutes of CPU time!

(3) convert the required thread TID to hexadecimal format

[root@localhost ~] # printf "% x\ n" 3626 e18

(4) use the jstack command to print out the stack information of this thread under the process:

[root@localhost ~] # jstack 2633 | grep "E18"-A 30 "how to troubleshoot the problem of high CPU occupancy in Linux system" is introduced here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Threads processes commands binary information problems sorting rates systems content stacks faults methods more formats cases knowledge procedures positioning utility Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS Huawei vpn Microsoft