linux cpu占有率居高不下 调试
今天调试程序,使用top命令后,发现程序的cpu占有率很高,一直在99,这很可怕,所以来调试。
使用top命令,得如下结果
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1997 root 20 0 358m 71m 3208 S 99.1 7.2 81:53.50 test
1 root 20 0 24332 2044 1176 S 0.0 0.2 0:01.36 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:46.51 ksoftirqd/0
4 root 20 0 0 0 0 S 0.0 0.0 0:38.53 kworker/0:0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
可知test的PID为1997
然后具体查看test里线程的cpu使用情况
使用 top -H -p 1997 命令
root@slk:~# top -H -p 1997
top - 17:19:47 up 15 days, 34 min, 4 users, load average: 1.02, 1.06, 1.06
Tasks: 8 total, 1 running, 7 sleeping, 0 stopped, 0 zombie
Cpu(s): 99.3%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.3%si, 0.3%st
Mem: 1017924k total, 887500k used, 130424k free, 85928k buffers
Swap: 0k total, 0k used, 0k free, 351280k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2005 root 20 0 358m 71m 3208 R 99.3 7.2 83:44.47 test
2001 root 20 0 358m 71m 3208 S 0.3 7.2 0:08.66 test
2004 root 20 0 358m 71m 3208 S 0.3 7.2 0:19.61 test
1997 root 20 0 358m 71m 3208 S 0.0 7.2 0:26.24 test
1999 root 20 0 358m 71m 3208 S 0.0 7.2 0:00.06 test
2000 root 20 0 358m 71m 3208 S 0.0 7.2 0:00.00 test
2002 root 20 0 358m 71m 3208 S 0.0 7.2 0:05.86 Server Listen(2
2003 root 20 0 358m 71m 3208 S 0.0 7.2 0:00.00 Server Accept(2
可得线程中CPU占有率最高的线程的PID是2005
使用gdb icdn 2005 命令
root@slk:~# gdb icdn 2005
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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 "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
icdn: No such file or directory.
Attaching to process 2005
warning: process 2005 is a cloned process
Reading symbols from /home/slk/test/snmptrapd...done.
Reading symbols from /usr/lib/libnetsnmp.so.30...done.
Loaded symbols for /usr/lib/libnetsnmp.so.30
Reading symbols from /lib/x86_64-linux-gnu/libpthread.so.0...(no debugging symbols found)...done.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Loaded symbols for /lib/x86_64-linux-gnu/libpthread.so.0
Reading symbols from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
Reading symbols from /usr/local/lib/libstd.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libstd.so
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libc.so.6
Reading symbols from /lib/x86_64-linux-gnu/librt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/librt.so.1
Reading symbols from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib/x86_64-linux-gnu/libz.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libz.so.1
Reading symbols from /lib/x86_64-linux-gnu/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libdl.so.2
Reading symbols from /lib/x86_64-linux-gnu/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libm.so.6
Reading symbols from /usr/local/lib/libudt.so...(no debugging symbols found)...done.
Loaded symbols for /usr/local/lib/libudt.so
Reading symbols from /usr/lib/x86_64-linux-gnu/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libstdc++.so.6
Reading symbols from /lib/x86_64-linux-gnu/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libgcc_s.so.1
Reading symbols from /lib/x86_64-linux-gnu/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libnss_files.so.2
execute_search () at test.c:310
从最后一行可知,线程2005运行的是execute_search这个函数,然后查看该函数,发现有这样一段
while(g_search_state == 1)
{
tmp = g_data_list->phead->next;
if (tmp)
{
pthread_mutex_lock(&g_mysql_mutex);
res.result = search_mysql(tmp->sn, &(res.machine));
pthread_mutex_unlock(&g_mysql_mutex);
snprintf(res.sn, sizeof(res.sn), "%s", tmp->sn);
}
}
由于tmp长期为NULL,所以这变成了一个while的死循环,而死循环极为占用内存,于是再下面加上usleep(50000),问题解决
linux cpu占有率居高不下 调试的更多相关文章
- Linux下高cpu占有率的调试方案
1.用top命令查看哪个进程占用CPU高 gateway网关进程14094占用CPU高达891%,这个数值是进程内各个线程占用CPU的累加值. 2.用top -H -p pid命令查看进程内各个线 ...
- Shell脚本 | 性能测试之CPU占有率
Android 是一个基于 Linux 内核的移动操作系统,Linux 的 CPU 占有率的计算方式也可以应用到 Android App 上. 今天分享的这个脚本的功能,是在多核情况下计算进程的 CP ...
- linux上使用J-Link调试S3C2440裸机代码
linux上使用J-Link调试S3C2440裸机代码 工具: segger的jlink仿真器 segger的jlink for linux 交叉编译工具链里面的arm-xx-linux-xx-gdb ...
- Oracle 11g中查询CPU占有率高的SQL
oracle版本:oracle11g 背景:今天在Linux中的oracle服务上,运用top命令发现许多进程的CPU占有率是100%. 操作步骤: 以进程PID:7851为例 执行以下语句: 方法一 ...
- Atitit. 获取cpu占有率的 java c# .net php node.js的实现
Atitit. 获取cpu占有率的 java c# .net php node.js的实现 通过wmic接口获取cpu占有率 C:\Users\Administrator.ATTILAXPC188&g ...
- Linux的段错误调试方法
linux段错误的调试方法 相关博文: http://blog.csdn.net/htianlong/article/details/7439030 http://www.cnblogs.com/pa ...
- Linux驱动设计—— 驱动调试技术
参考博客与书籍: <Linux设备驱动开发详解> <Linux设备驱动程序> http://blog.chinaunix.net/uid-24219701-id-2884942 ...
- Linux CPU亲缘性详解
前言 在淘宝开源自己基于nginx打造的tegine服务器的时候,有这么一项特性引起了笔者的兴趣.“自动根据CPU数目设置进程个数和绑定CPU亲缘性”.当时笔者对CPU亲缘性没有任何概念,当时作者只是 ...
- 查看线程linux cpu使用率
Linux下如何查看高CPU占用率线程 LINUX CPU利用率计算 转 http://www.cnblogs.com/lidabo/p/4738113.html目录(?)[-] proc文件系统 p ...
随机推荐
- Scalaz(26)- Lens: 函数式不可变对象数据操作方式
scala中的case class是一种特殊的对象:由编译器(compiler)自动生成字段的getter和setter.如下面的例子: case class City(name:String, pr ...
- hdu-1213-How Many Tables
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- jquery easyui 弹出消息框 (转载) jQuery EasyUI API 中文文档 - 消息框(Messager) http://www.cnblogs.com/hantianwei/archive/2012/03/19/2407113.html
<html> <head> <!-- 导入easyui插件的js和css样式; --> <link rel="stylesheet" ty ...
- python 学习笔记7(装饰器)
闭包(closure)是函数式编程的重要的语法结构. 定义:如果在一个内部函数里,对在外部作用域(但不是在全局作用域)的变量进行引用,那么内部函数就被认为是闭包(closure). def outer ...
- 一个完整的类用来生成RSACryptoServiceProvider单例类(.NET)
internal class CcbRsaCryptProvider { private static RSACryptoServiceProvider _providerForSign; priva ...
- servlet的开发流程介绍
servlet的开发部署流程 1.在%TOMCAT_HOME%/webapps下WEB-INF的文件夹,写一个文件web.xml(该网站的配置信息),建立一个classes的子文件夹,也可以从别的目录 ...
- Shepherd – 在应用程序中轻松实现引导功能
Shepherd 是一个指导用户使用应用程序的 JavaScript 库.它使用 Tether——另一个开源库,实现所有的步骤.Tether 确保你的步骤不会溢出屏幕或被剪裁.你可以很容易地指导用户使 ...
- sharepoint 2013 持续爬网
能否对所有类型的内容源都使用连续爬网?不能.连续爬网仅适用于 SharePoint 型内容源.所有其他类型的内容源将继续选择增量爬网和完全爬网. 使用连续爬网是否会给存储库增加额外负载?连续爬网的资源 ...
- git 设置 key 到服务器,同步代码不需要输入用户名和密码
1 ssh-keygen -t rsa 2 vim ~/.ssh/id_rsa.pub 3. 添加到git 服务器,这样同步代码就不需要输入密码
- exec
之前一直这样显示 不知道修改了什么,变成了这样. 在终端 找到这个podfile所在的目录 chmod 600 podfile 然后 就变回来了.可能是修改权限的问题.