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.
如果程序在運(yùn)行期間發(fā)生崩潰,操作系統(tǒng)會(huì)生成一個(gè)core dump文件,之后通過對(duì)core dump文件進(jìn)行分析可以獲取程序崩潰的原因
默認(rèn)情況下,Linux 不允許生成core dump文件
# 設(shè)置core大小為無限
ulimit -c unlimited
# 查看當(dāng)前允許core文件大小
ulimit -c
修改/proc/sys/kernel/core_uses_pid,可以把進(jìn)程的pid作為core文件的擴(kuò)展名
修改/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調(diào)試對(duì)core文件進(jìn)行分析
gdb program core文件
bt