ulimit
1 | #查看配置 |
ulimit
只对当前终端有效。
以下两种方法对所有用户和终端有效:
- 在
/etc/security/limits.conf
中设置(redhat衍生系linux)。 - 或注释掉
/etc/profile
中的这一行:1
2# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
core_pattern
core_pattern解释
见链接。
Read /usr/src/linux/Documentation/sysctl/kernel.txt.
core_pattern is used to specify a core dumpfile pattern name.
在系统启动时,Apport(crash reporting service)会生成配置文件/proc/sys/kernel/core_pattern
。参考这里。
Apport uses /proc/sys/kernel/core_pattern
to directly pipe the core dump into apport
:
1 | $ cat /proc/sys/kernel/core_pattern |
Note that even if ulimit
is set to disabled core files (by specyfing a core file size of zero using ulimit -c 0
), apport
will still capture the crash.
For intercepting Python crashes it installs a /etc/python*/sitecustomize.py
to call apport on unhandled exceptions.
其中,/usr/share/apport/apport
是一个python脚本。
以下是core_pattern文件的参数说明(参考Linux Manual Page:man core
):
1 | %c - Core file size soft resource limit of crashing process (since Linux 2.6.24). |
Apport的拦截组件默认是关闭的:
Apport itself is running at all times because it collects crash data for whoopsie (see ErrorTracker). However, the crash interception component is still disabled. To enable it permanently, do:
1 | sudo nano /etc/apport/crashdb.conf |
… and add a hash symbol # in the beginning of the following line:
'problem_types': ['Bug', 'Package'],
To disable crash reporting just remove the hash symbol.
设置core_pattern
见链接。
/proc/sys/kernel/core_uses_pid可以控制产生的core文件的文件名中是否添加pid作为扩展,如果添加则文件内容为1,否则为0;
/proc/sys/kernel/core_pattern可以设置格式化的core文件保存位置或文件名:
1
2
3$ cat /proc/sys/kernel/core_pattern
|/usr/share/apport/apport %p %s %c
$ echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern你可以用下列方式来完成:
1
2
3
4#查看所有sysctl所有变量的值。
sysctl -a
#设置变量kernel.core_pattern为如下值。
sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t这些操作一旦计算机重启,则会丢失,如果你想持久化这些操作,可以在 /etc/sysctl.conf文件中增加:
1
kernel.core_pattern=/tmp/core%p
加好后,如果你想不重启看看效果的话,则用下面的命令:
1
sysctl -p /etc/sysctl.conf
相关命令行工具
参考资料:
Linux Manual Page: man core
SEE ALSO
bash(1), coredumpctl(1), gdb(1), getrlimit(2), mmap(2), prctl(2), sigaction(2), elf(5), proc(5), pthreads(7), signal(7), systemd-coredump(8)
Segment Fault排查
参考链接。