【gdb】coredump
coredump
1. 在终端中输入ulimit -c 如果结果为0,说明当程序崩溃时,系统并不能生成core dump。可以使用命令 ulimit -c unlimited 来开启 core dump 功能,并且不限制 core dump 文件的大小; 如果需要限制文件的大小,将 unlimited 改成你想生成 core 文件最大的大小,注意单位为 blocks(KB):
ulimit -c unlimited
3. /proc/sys/kernel/core_uses_pid可以控制core文件的文件名中是否添加pid作为扩展。文件内容为1,表示添加pid作为扩展名,生成的core文件格式为core.xxxx;为0则表示生成的core文件同一命名为core。
可通过以下命令修改此文件:
echo "1" > /proc/sys/kernel/core_uses_pid
4. 通过修改/proc/sys/kernel/core_pattern可以控制core文件保存位置和文件格式。例如:将所有的core文件生成到/corefile目录下,文件名的格式为core-命令名-pid-时间戳.
echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern
以下是参数表:
- %p - insert pid into filename 添加pid
- %u - insert current uid into filename 添加当前uid
- %g - insert current gid into filename 添加当前gid
- %s - insert signal that caused the coredump into the filename 添加导致产生core的信号
- %t - insert UNIX time that the coredump occurred into filename 添加core文件生成时的unix时间
- %h - insert hostname where the coredump happened into filename 添加主机名
- %e - insert coredumping executable name into filename 添加命令名
在 /etc/sysctl.d/50-coredump.conf设置:
kernel.core_pattern=|usr/lib/systemd/system-coredump %P %u %g %s %t %c %e
在 /etc/systemd/coredump.conf设置:
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See coredump.conf(5) for details.
[Coredump]
Storage=external
Compress=yes
ProcessSizeMax=10G
ExternalSizeMax=10G
#JournalSizeMax=767M
MaxUse=20G
KeepFree=4G
启动配置文件:
chmod 644 /etc/systemd/*
chmod 644 /etc/sysctl.d/*
sysctl -p /etc/sysctl.d/*.conf
参考资料
1. 解决linux下不生成core dump文件
2. systemd-coredump, systemd-coredump.socket, systemd-coredump@.service — Acquire, save and process core dumps
3. linux下生成core dump文件方法及设置

浙公网安备 33010602011771号