when we write a program, cpu and memory usages are very important to indicate the stability of the program. Once the cpu usage reached 90%, there are some bugs in your program, and you must find the problem. Here is a simply guide to debug with cpu 100%. For example:

void *first_routine (void * args)
{
while()
{
int a = ;
usleep();
} return NULL;
} int main()
{
pthread_t thread_first, thread_second;
pthread_create(&thread_first, NULL, &first_routine, NULL); while()
{
sleep();
}
return ;
}

then complile it : gcc debug.c -o debug -lpthread , and run it .

iii) use top tool find the bug thread,  top -p $pid -H

iv) use pstack : pstack $tid(bug thread), to look the stack of the bug thread. but pstack can't see the paraments. if you still can't determine the bug line, user gcore to get the program core.  (gcore $pid)

v)  gdb -c  $core.file  ./exe , and the use  command  bt(back trace), then use the paraments to determine the bug code.

how to debug thread cpu 100%的更多相关文章

  1. 解决new Thread().Start导致高并发CPU 100%的问题

    背景 之前接手一个项目的时候,发现到处是 new Thread(()=>{ //do something }).Start(); 这么做的目的,无非是为了减少页面等待时间提高用户体验,把一些浪费 ...

  2. [Java] CPU 100% 原因查找解决

    CPU 100%肯定是出现死锁,这个时候观察内存还是够用的,但是CPU一直100%,以下几步解决: 1. 找到进程消耗cpu最大的 $top top - :: up days, :, user, lo ...

  3. Linux系统cpu 100%修复案例

    Linux系统cpu 100%修复案例 ​阿里云技术支持团队:完颜镇江 案例背景: Linux主机连续三天CPU% 处理思路: 1.  登录服务器查看/var/log/messages+/var/lo ...

  4. 系统运行缓慢,CPU 100%,以及Full GC次数过多问题的排查思路

    前言 处理过线上问题的同学基本上都会遇到系统突然运行缓慢,CPU 100%,以及Full GC次数过多的问题.当然,这些问题的最终导致的直观现象就是系统运行缓慢,并且有大量的报警. 本文主要针对系统运 ...

  5. Linux(2)---记录一次线上服务 CPU 100%的排查过程

    Linux(2)---记录一次线上服务 CPU 100%的排查过程 当时产生CPU飙升接近100%的原因是因为项目中的websocket时时断开又重连导致CPU飙升接近100% .如何排查的呢 是通过 ...

  6. JDK8的ConcurrentHashMap也会造成CPU 100%

    转载:不止 JDK7 的 HashMap ,JDK8 的 ConcurrentHashMap 也会造成 CPU 100%?原因与解决~ 现象 大家可能都听过JDK7中的HashMap在多线程环境下可能 ...

  7. Java死锁排查和Java CPU 100% 排查的步骤整理

    ================================================= 人工智能教程.零基础!通俗易懂!风趣幽默!大家可以看看是否对自己有帮助! 点击查看高清无码教程 == ...

  8. 线上服务 CPU 100%?一键定位 so easy!

      转自:  https://my.oschina.net/leejun2005/blog/1524687   摘要: 本文主要针对 Java 服务而言 0.背景 经常做后端服务开发的同学,或多或少都 ...

  9. 一文学会Java死锁和CPU 100% 问题的排查技巧

    做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开 工欲善其事,必先利其器 00 本文简介 作为一名搞技术的程序猿或者是攻城狮,想必你应该是对下面这两个问题有所了解,说不定你在 ...

随机推荐

  1. 用iDSDT制作声显卡DSDT

    已有 2299 次阅读2011-10-24 21:00 |个人分类:Mac| DSDT 快速增加积分秘笈! windows下!--------------------------------第一步.下 ...

  2. 安装apache2.4.10

    一:依赖安装:apache依赖于apr,apr-util,pcre,所以需要先安装他,并且需要最新的 apr官网:http://apr.apache.org/download.cgi pcre官网:h ...

  3. Foundation学习笔记

    . 链接:Foundation学习,代码实例总结(pdf版) .

  4. tachyon 本地模式安装

    本地模式不用考虑hadoop的版本,所以直接下载 binary 包或者自己编译 1.配置主机名.JDK.关闭防火墙.关闭Selinux.配置hosts ... ... 2.设置本机SSH免密码登陆 . ...

  5. 解决Lost connection to MySQL server at 'reading initial communication packet', 的方法

    今天用heidsql连接mysql时出了问题,提示:Lost connection to MySQL server at 'reading initial communication packet 网 ...

  6. Intervals poj 1201 差分约束系统

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22503   Accepted: 8506 Descri ...

  7. solr--搜索参数随笔

    1.默认搜索域.查询域的关系 qf字段的配置:query fields,指定solr从哪些field中搜索 在solrj中设置如下: params.setParam("qf", & ...

  8. 测试 IE 浏览器兼容性 VirtualBox + modern.ie

    VirtualBox 是开源的虚拟机软件,常用的虚拟机软件还有 VMware / Hyper-V / Paralles Desktop . modern.ie 是微软官方提供的用于测试网页在各版本 I ...

  9. 【python,threading】python多线程

    使用多线程的方式 1.  函数式:使用threading模块threading.Thread(e.g target name parameters) import time,threading def ...

  10. 能够提高开发效率的Eclipse实用操作

    工欲善其事,必先利其器.对于程序员来说,Eclipse便是其中的一个“器”.本文会从Eclipse快捷键和实用技巧这两个篇章展开介绍.Eclipse快捷键用熟后,不用鼠标,便可进行编程开发,避免鼠标分 ...