六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 30|回复: 0

Controlling core files (Linux)

[复制链接]

升级  93.33%

52

主题

52

主题

52

主题

秀才

Rank: 2

积分
190
 楼主| 发表于 2013-1-26 12:35:02 | 显示全部楼层 |阅读模式

Controlling core files (Linux)

core file文件重定位:echo /tmp/core.%e.%p > /proc/sys/kernel/core_pattern
 

Core files get created when a program misbehaves due to a bug, or a violation of the cpu or memory protection mechanisms. The operating system kills the program and creates the core file.
If you don't want core files at all, set "ulimit -c 0" in your startup files. That's the default on many systems; in /etc/profile you may find 




ulimit -S -c 0 > /dev/null 2>&1  If you DO want core files, you need to reset that in your own .bash_profile:
ulimit -c 50000  


would allow core files but limit them to 50,000 bytes.
You have more control of core files in /proc/sys/kernel/
For example, you can do eliminate the tagged on pid by
echo "0" > /proc/sys/kernel/core_uses_pid  


Core files will then just be named "core". People do things like that so that a user can choose to put a non-writable file named "core" in directories where they don't want to generate core dumps. That could be a directory (mkdir core) or a file (touch core;chmod 000 core). I've seen it suggested that a symlink named core would redirect the dump to wherever it pointed, but I found that didn't work.
But perhaps more interesting is that you can do: 

mkdir /tmp/corefiles chmod 777 /tmp/corefiles echo "/tmp/corefiles/core" > /proc/sys/kernel/core_pattern  All corefiles then get tossed to /tmp/corefiles (don't change core_uses_pid if you do this).
Test this with a simple script:
# script that dumps core kill -s SIGSEGV $$
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表