Ubuntu 1804 And Above Coredump Settings

查看 coredump 是否开启

bash 复制代码
# 查询, 0 未开启, unlimited 开启
xiao@Ubuntu:/var/core$ ulimit -c
0

# 开启
xiao@Ubuntu:/var/core$ ulimit -c unlimited

查看 coredump 保存路径

默认情况下,Ubuntu 使用 apport 服务处理 coredump 文件,不会将 coredump 保存到程序运行的目录下。

bash 复制代码
xiao@Ubuntu:~/Desktop/crash$ cat /proc/sys/kernel/core_pattern
|/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E

# If the first character of the pattern is a '|', the kernel will treat
# the rest of the pattern as a command to run.  The core dump will be
# written to the standard input of that program instead of to a file.

disable ubuntu apport service through systemctl

bash 复制代码
# 关闭 ubuntu 官方错误收集服务
sudo systemctl disable apport.service
sudo systemctl stop apport.service

# 开启 ubuntu 官方错误收集服务
sudo systemctl enable apport.service
sudo systemctl start apport.service

disable ubuntu apport service through config file

bash 复制代码
xiao@Ubuntu:~/Desktop/crash$ cat /etc/default/apport 
# set this to 0 to disable apport, or to 1 to enable it
# you can temporarily override this with
# sudo service apport start force_start=1
enabled=1

关闭 apport servie 后,查看 /proc/sys/kernel/core_pattern 文件

bash 复制代码
xiao@Ubuntu:~/Desktop/crash$ cat /proc/sys/kernel/core_pattern 
core

使用 systemd-coredump 服务处理 coredump 文件

也可以使用 systemd-coredump 服务管理 coredump 文件,如下所示。

bash 复制代码
xiao@Ubuntu:~/Desktop/crash$ cat /proc/sys/kernel/core_pattern
|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %e

手动安装 systemc-coredump 服务

bash 复制代码
sudo apt install systemd-coredump
# Reset all sysctl settings. Default no need to run.
systemctl restart systemd-sysctl

如果使用 systemd-coredump 服务,我们可以使用 coredumpctl 命令查看 coredump 文件。默认的,coredump 文件保存于 /var/lib/systemd/coredump/ 目录下。


永久修改 coredump 文件名或保存路径

/etc/sysctl.conf 和 /etc/sysctl.d/ 目录下都可以修改配置,如果修改/etc/sysctl.conf 不生效,需要确认 /etc/sysctl.d/ 目录下有没有已定义的配置,将会覆盖 /etc/sysctl.conf中的配置.

bash 复制代码
# 需要 root 权限,确保你的 conf 配置不会被覆盖
sudo bash && echo "kernel.core_pattern=/var/core/core_%e_%p" > /etc/sysctl.d/100-coredump.conf
# load config. if no config file, /etc/sysctl.conf is default.
sudo sysctl --p /etc/sysctl.d/100-coredump.conf

临时修改 coredump 文件名或保存路径

bash 复制代码
sysctl -w kernel.core_pattern="%e-%s.core"

References

相关推荐
xiaobin889991 小时前
【2025最新版】VMware虚拟机下载安装教程 保姆级图文详解(附安装包+常用镜像Linux,win11,ubuntu,centos)
linux·其他·ubuntu·centos
ALex_zry2 小时前
Ubuntu 20.04 C++开发环境搭建指南(2025版)
linux·c++·ubuntu
Eric.Lee202116 小时前
Ubuntu shell指定conda的python环境启动脚本
python·ubuntu·conda·shell
dubochao_xinxi21 小时前
✅ TensorRT Python 安装精简流程(适用于 Ubuntu 20.04+)
开发语言·python·ubuntu
yangshuo12811 天前
风车OVF镜像:解放AI开发限制的Ubuntu精简系统
linux·人工智能·ubuntu
flypig哗啦啦1 天前
ubuntu服务器版启动卡在start job is running for wait for...to be Configured
linux·运维·ubuntu
子非衣1 天前
Ubuntu系统挂载磁盘并配置开机自动挂载
linux·运维·ubuntu
ChironW1 天前
Ubuntu 22.04.5 LTS上部署Docker及相关优化
ubuntu·docker·容器
richer_20201 天前
双系统重装ubuntu
linux·运维·ubuntu
微学AI1 天前
用FileCodeBox打造私有文件传输:Ubuntu环境保姆级部署教程!
linux·运维·ubuntu