core dump调查方法

core dump概念

A core dump is the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally (crashed). In practice, other key pieces of program state are usually dumped at the same time, including the processor registers, which may include the program counter and stack pointer, memory management information, and other processor and operating system flags and information. The name comes from the once-standard memory technology core memory. Core dumps are often used to diagnose or debug errors in computer programs.

On many operating systems, a fatal error in a program automatically triggers a core dump, and by extension the phrase "to dump core" has come to mean, in many cases, any fatal error, regardless of whether a record of the program memory is created.

如果程序在运行期间发生崩溃,操作系统会生成一个core dump文件,之后通过对core dump文件进行分析可以获取程序崩溃的原因

默认情况下,Linux 不允许生成core dump文件

# 设置core大小为无限
ulimit -c unlimited
# 查看当前允许core文件大小
ulimit -c

修改/proc/sys/kernel/core_uses_pid,可以把进程的pid作为core文件的扩展名
修改/proc/sys/kernel/core_pattern,可以控制core文件保存位置和文件格式

echo 1 > /proc/sys/kernel/core_uses_pid                             # core.pid
echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern      # core-cmd-pid-timestamp

通过gdb调试对core文件进行分析

gdb program core文件
bt
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容