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. 关于CQRS(老外经典好文)

    CQRS means Command Query Responsibility Segregation. Many people think that CQRS is an entire archit ...

  2. Android精品课程—PullToRefresh 下拉刷新

    http://edu.csdn.net/course/detail/1716 TableLayout http://edu.csdn.net/course/detail/2262 Android开发之 ...

  3. Docker大行其道—镜像

    导读 作为Docker三大核心概念之一,Docker镜像(Docker Image)是一个面向Docker引擎的只读模板,包含文件系统.实际上每个Docker镜像包含一个独立的运行环境,如一个镜像包含 ...

  4. mysql常用备注

    一:One Table  have only one Auto_Increment that column is must to be Primary key. (自增加的字段必须是主键且是数字类型) ...

  5. SQL Server 中的事务和锁(三)-Range S-U,X-X 以及死锁

    在上一篇中忘记了一个细节.Range T-K 到底代表了什么?Range T-K Lock 代表了在 SERIALIZABLE 隔离级别中,为了保护范围内的数据不被并发的事务影响而使用的一类锁模式(避 ...

  6. 阮一峰博客里面css3的display:flex的布局

  7. Android之EditText文本变化的监听

    监听EditText的文本变化需要给EditText控件加一个addTextChangeListener监听器 editText.addTextChangeListener(textWatcher); ...

  8. (转)JavaScript 中对变量和函数声明的“提前(hoist)”

    变量声明“被提前” JavaScript 的语法和 C .Java.C# 类似,统称为 C 类语法.有过 C 或 Java 编程经验的同学应该对“先声明.后使用”的规则很熟悉,如果使用未经声明的变量或 ...

  9. 原生js显示分页效果

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  10. MySQL配置文件my.cnf参数优化和中文详解

    Mysql参数优化对于新手来讲,是比较难懂的东西,其实这个参数优化,是个很复杂的东西,对于不同的网站,及其在线量,访问量,帖子数量,网络情况,以及机器硬件配置都有关系,优化不可能一次性完成,需要不断的 ...