how to debug thread cpu 100%
2024-10-19 11:51:41
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.
最新文章
- 学习笔记--C#深复制和浅复制
- 通过端口 8080 连接到主机 localhost 的 TCP/IP 连接失败
- linux系统中批量查找文件与文件内容的方法
- 1、Hadoop的伪分布式部署
- JDK、Jmeter、Android环境变量配置
- 夺命雷公狗-----React---3--标签的规则
- Python 时间和日期模块的常用例子
- 关于新的man版本出现“无法解析 /usr/share/man/zh_CN/man1/ls.1.gz: 没有那个文件或目录“
- DAC,MAC和SELinux,SEAndroid
- 3.0:pandas【基础操作】
- JDBC连接数据以及操作数据
- angularjs directive (自定义标签解析)
- Anagram
- Java I/O流详解与应用
- 访问System x3650 IMM2的几种方式
- WSGI协议主要包括server和application两部分:
- git 工作区管理
- shell_base
- 清北合肥day1
- 【R作图】lattice包,画多个分布柱形图,hist图纵轴转换为百分比