High CPU usage of processes in Linux

Source: Internet
Author: User
Tags high cpu usage

From: http://blog.csdn.net/ligt0610/article/details/7265903

1. Use the TOP command to find the process with the highest CPU utilization
Root @ xxx :/#Top
Top-09:36:26 up 22 min, 2 users, load average: 6.02, 5.10, 3.58
Tasks: 43 total, 1 running, 42 sleeping, 0 stopped, 0 zombie
CPU (s): 1.0% us, 12.6% Sy, 0.0% Ni, 86.4% ID, 0.0% wa, 0.0% hi, 0.0% Si, 0.0% St
Mem: 514336 k total, 53156 K used, 461180 K free, 6776 K Buffers
Swap: 0 k total, 0 K used, 0 K free, 24072 K cached

PID user PR Ni virt res shr s % CPU % mem time + command
1145 root 20 0 539 m 6008 2940 s 65.9. 77 test. Out
6 root 15-5 0 0 s 0.3 0.0. 13 khelper
1327 root 20 0 3352 1372 s 1136 0.3. 01 run
12465 root 20 0 8432 2300 s 1932 0.3. 07 sshd
1 root 20 0 2436 704 s 616 0.0. 73 init
2 root 15-5 0 0 s 0.0 0.0. 00 kthreadd

2. Find the thread with the longest CPU usage by the corresponding process
Root @ xxx :/#PS-EFL | grep test. Out | grep-V grep
Uid pid ppid lwp C nlwp stime tty time cmd
Root 1145 1 1145 0 62? 00:00:03/home/ligt/bin/test. Out
Root 1145 1 1148 0 62? 00:00:01/home/ligt/bin/test. Out
Root 1145 1 1149 0 62? 00:00:03/home/ligt/bin/test. Out
Root 1145 1 1151 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1152 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1153 0 62? 00:00:06/home/ligt/bin/test. Out
Root 1145 1 1154 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1155 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1157 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1158 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1159 0 62? 00:00:06/home/ligt/bin/test. Out
Root 1145 1 1160 0 62? 00:00:01/home/ligt/bin/test. Out
Root 1145 1 1161 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1162 10 62? 00:02:41/home/ligt/bin/test. Out
Root 1145 1 1163 0 62? 00:00:01/home/ligt/bin/test. Out
Root 1145 1 1164 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1165 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1166 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1167 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1169 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1170 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1171 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1172 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1173 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1174 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1175 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1176 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1177 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1178 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1179 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1180 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1181 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1182 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1183 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1186 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1187 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1188 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1189 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1192 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1193 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1194 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1195 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1196 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1197 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1198 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1199 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1200 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1201 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1202 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1203 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1204 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1205 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1206 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1207 0 62? 00:00:00/home/ligt/bin/test. Out
Root 1145 1 1208 0 62? 00:00:00/home/ligt/bin/test. Out

3. attach to the corresponding thread
Root @ xxx :/#GDB attach 1162
Gnu gdb (Wind River Linux sourcery g ++ 4.3a-274) 6.8.50.20080821-CVS
Copyright (c) 2008 Free Software Foundation, Inc.
License gplv3 +: gnu gpl Version 3 or later This is free software: You are free to change and redistribute it.
There is no warranty, to the extent permitted by law. Type "show copying"
And "show warranty" for details.
This GDB was configured as "PowerPC-WRS-Linux-GNU ".
For bug reporting instructions, please see:
<Support@windriver.com>...
Attach: no such file or directory.
Attaching to process 1162

Warning: Process 1162 is a cloned Process
Reading symbols from/common/home/ligt/bin/test. Out... done.
Reading symbols from/lib/libcrypt. so.1.... done.
Loaded symbols for/lib/libcrypt. so.1
Reading symbols from/usr/lib/libmscm_auth.so... done.
Loaded symbols for/usr/lib/libmscm_auth.so
Reading symbols from/usr/lib/libmscm_ldap.so... done.
Loaded symbols for/usr/lib/libmscm_ldap.so
Reading symbols from/usr/lib/libmscm_eclipparse.so... done.
Loaded symbols for/usr/lib/libmscm_eclipparse.so
Reading symbols from/usr/lib/libldap-2.4.so.2... done.
Loaded symbols for/usr/lib/libldap-2.4.so.2
Reading symbols from/usr/lib/liblber-2.4.so.2... done.
Loaded symbols for/usr/lib/liblber-2.4.so.2
Reading symbols from/lib/libdl. so.2.... done.
Loaded symbols for/lib/libdl. so.2
Reading symbols from/usr/lib/libstdc ++. so.6... done.
Loaded symbols for/usr/lib/libstdc ++. so.6
Reading symbols from/lib/libm. so.6...... done.
Loaded symbols for/lib/libm. so.6
Reading symbols from/lib/libgcc_s.so.1... done.
Loaded symbols for/lib/libgcc_s.so.1
Reading symbols from/lib/libpthread. so.0.... done.
Loaded symbols for/lib/libpthread. so.0
Reading symbols from/lib/libc. so.6...... done.
Loaded symbols for/lib/libc. so.6
Reading symbols from/lib/libresolv. so.2.... done.
Loaded symbols for/lib/libresolv. so.2
Reading symbols from/lib/lD. so.1. .. Done.
Loaded symbols for/lib/lD. so.1
Reading symbols from/lib/libnss_files.so.2... done.
Loaded symbols for/lib/libnss_files.so.2
0x0ff1dbf0 in select () from/lib/libc. so.6
(GDB) BT
#0 0x0ff1dbf0 in select () from/lib/libc. so.6
#1 0x101396cc in osal_taskdelay (ulmillsecs = <value optimized out>)
At/home/ligt/IPMI/src/vos/ipmi_osal_task.c: 498
#2 0x101307a8 in vos_taskdelay (ulmillsecs = <value optimized out>) at/home/ligt/IPMI/src/vos/ipmi_v_task.c: 3512
#3 0x10089ed4 in cipmb_processor: onsend (this = 0x103cc0a8) at/home/ligt/IPMI/src/IPMI/ipmbproc. cpp: 3422
#4 0x10132db8 in vos_taskentry (pularg = 0x1000d) at/home/ligt/IPMI/src/vos/ipmi_v_task.c: 3459
#5 0x0fdf6d8c in ?? () From/lib/libpthread. so.0
#6 0x0ff25a90 in clone () from/lib/libc. so.6
(GDB) q
The program is running. Quit anyway (and detach it )? (Y or N) y
Detaching from program:/home/ligt/bin/test. Out, process 1162

Through the above three-step analysis, you can basically find out which codes cause high CPU usage and hope to help your friends who encounter the same problems.

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.