Linux 系统中 Core 文件

 
 
dump文件可以在程序crash时,方便我们查看程序crash的地方和上下文信息。
 
问题一:Core 文件产生的开关
 
1. 查看当前是否已经打开了此开关
通过命令:ulimit -c 如果输出为0 ,则代表没有打开。(通过命令:ulimit -c 1   就可以打开开关),
如果输出为1,代表已经打开。如果要取消:ulimit -c 0  就可以了。
 
2. 第二种打开开关的命令是:ulimit -c unlimited
 
3. 通过上面的命令修改后,一般都只是对当前会话起作用,当你下次重新登录后,还是要重新输入上面的命令,所以很麻烦。我们可以把通过修改
/etc/profile文件来使系统每次自动打开。
步骤如下:
1>,首先打开/etc/profile文件一般都可以在文件中找到
这句语句:ulimit -S -c 0 > /dev/null 2>&1.ok,根据上面的例子,我们只要把那个0 改为unlimited ok了。然后保存退出。
2>, 通过source /etc/profile 使当期设置生效。
3>, 通过ulimit -c 查看下是否已经打开。
其实不光这个命令可以加入到/etc/profile文件中,一些其他我们需要每次登录都生效的都可以加入到此文件中,因为登录时linux都会加载此文件。比如一些环境变量的设置。
还有一种方法可以通过修改/etc/security/limits.conf文件来设置,这个方法没有试过,也是网上看到。不过上面两种就可以了!
 最后说一下生成core dump文件的位置,默认位置与可执行程序在同一目录下,文件名是core.***,其中***是一个数字。core
dump文件名的模式保存在/proc/sys/kernel/core_pattern中,缺省值是core。通过以下命令可以更改core
dump文件的位置(如希望生成到/tmp/cores目录下)
echo “/tmp/cores/core” > /proc/sys/kernel/core_pattern
问题二:为何有时程序Down了,却没生成Core文件。

Linux下,有一些设置,标明了resourcesavailable to the shell and to processes。可以使用

#ulimit-a来看这些设置。(ulimitbashbuilt-in Command)

-a All current limits are reported
-c The maximum size of corefiles created
-d The maximum size of a process
鈥檚datasegment
-e The maximum scheduling priority ("nice")
-f The maximum size of files written by the shell and itschildren
-i The maximum number of pending signals
-l The maximum size that may be locked into memory
-m Themaximum resident set size (has no effect on Linux)
-n Themaximum number of open file descriptors (most systems do not allowthis value to be set)
-p The pipe size in 512-byte blocks(this may not be set)
-q The maximum number of bytes in POSIXmessage queues
-r The maximum real-time scheduling priority
-s The maximum stack size
-t The maximum amount of cputime in seconds
-u The maximum number of processes availableto a single user
-v The maximum amount of virtual memoryavailable to the shell
-x The maximum number of file locks

从这里可以看出,如果-c是显示:corefile size (blocks, -c)

如果这个值为0,则无法生成core文件。所以可以使用:

#ulimit-c 1024或者#ulimit-c unlimited来使能core文件。

如果程序出错时生成Core文件,则会显示Segmentationfault (core dumped)

问题三:使用gdb 调试 core文件
 
core文件所在目录下键入:
gdb -c core
它会启动GNU的调试器,来调试core文件,并且会显示生成此core文件的程序名,中止此程序的信号等等
如果你已经知道是由什么程序生成此core文件的,比如MyServer崩溃了生成core.12345,那么用此指令调试:
gdb -c core MyServer
 
参考文献:
http://blog.chinaunix.net/uid-26074921-id-2353637.html
http://www.cnblogs.com/dongzhiquan/archive/2012/01/20/2328355.html
https://my.oschina.net/u/1024573/blog/490816

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值