今天, 我们来介绍一个linux中的dmesg命令,事实上, 我们之前用过, 但是没有单独介绍过。
看一下dmesg命令的用途吧:
dmesg命令用会把开机信息存到ring bufer中, 形成一个缓冲, 免得你我来不及看。 在root权限下, 可以用dmesg -c来清楚这个消息。 单纯的一个dmesg命令则是用来输出这些记录信息的。
要注意, 程序core dump之后, 并不一定产生core文件, 此时, 我们的重要目的是: 获取出错堆栈的地址, 而dmesg命令可达此目的。
下面, 我们来看一下经典的dmesg + addr2line
[taoge@localhost test]$ cat test.c -n
1 #include <stdio.h>
2
3 int main()
4 {
5 int *p = NULL;
6 *p = 0;
7
8 printf("bad\n");
9 return 0;
10 }
[taoge@localhost test]$ gcc -g test.c
[taoge@localhost test]$ ./a.out
Segmentation fault (core dumped)
[taoge@localhost test]$
[taoge@localhost test]$
[taoge@localhost test]$
[taoge@localhost test]$ dmesg
a.out[3709]: segfault

本文介绍了Linux中的dmesg命令,它用于保存开机信息并提供查看系统错误的重要手段。在没有core文件的情况下,dmesg结合addr2line可以用于获取出错堆栈地址,帮助定位core dump问题。通过dmesg -c清除消息,或使用grep过滤信息,能够有效分析和解决堆栈异常。即便没有core文件,借助dmesg和日志,也能实现core dump的定位。
1842

被折叠的 条评论
为什么被折叠?



