(转)Linux core 文件介绍与处理
1. core文件的简单介绍
在一个程序崩溃时,它一般会在指定目录下生成一个core文件。core文件仅仅是一个内存映象(同时加上调试信息),主要是用来调试的。
2. 开启或关闭core文件的生成
用以下命令来阻止系统生成core文件:
ulimit -c 0
下面的命令可以检查生成core文件的选项是否打开:
ulimit -a
该命令将显示所有的用户定制,其中选项-a代表“all”。
也可以修改系统文件来调整core选项
在/etc/profile通常会有这样一句话来禁止产生core文件,通常这种设置是合理的:
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
但是在开发过程中有时为了调试问题,还是需要在特定的用户环境下打开core文件产生的设置
在用户的~/.bash_profile里加上ulimit -c unlimited来让特定的用户可以产生core文件
如果ulimit -c 0 则也是禁止产生core文件,而ulimit -c 1024则限制产生的core文件的大小不能超过1024kb
3. 设置Core Dump的核心转储文件目录和命名规则
/proc/sys/kernel/core_uses_pid可以控制产生的core文件的文件名中是否添加pid作为扩展,如果添加则文件内容为1,否则为0
/proc/sys/kernel/core_pattern可以设置格式化的core文件保存位置或文件名,比如原来文件内容是core-%e
可以这样修改:
echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern
将会控制所产生的core文件会存放到/corefile目录下,产生的文件名为core-命令名-pid-时间戳
以下是参数列表:
%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 添加命令名
4. 使用core文件
在core文件所在目录下键入:
gdb -c core
它会启动GNU的调试器,来调试core文件,并且会显示生成此core文件的程序名,中止此程序的信号等等
如果你已经知道是由什么程序生成此core文件的,比如MyServer崩溃了生成core.12345,那么用此指令调试:
gdb -c core MyServer
以下怎么办就该去学习gdb的使用了
5. 一个小方法来测试产生core文件
直接输入指令:
kill -s SIGSEGV $$
6. 为何有时程序Down了,却没生成 Core文件。
Linux下,有一些设置,标明了resources available to the shell and to processes。 可以使用
#ulimit -a 来看这些设置。 (ulimit是bash built-in Command)
-a All current limits are reported
-c The maximum size of core files created
-d The maximum size of a process鈥檚 data segment
-e The maximum scheduling priority ("nice")
-f The maximum size of files written by the shell and its children
-i The maximum number of pending signals
-l The maximum size that may be locked into memory
-m The maximum resident set size (has no effect on Linux)
-n The maximum number of open file descriptors (most systems do not allow this value to be set)
-p The pipe size in 512-byte blocks (this may not be set)
-q The maximum number of bytes in POSIX message queues
-r The maximum real-time scheduling priority
-s The maximum stack size
-t The maximum amount of cpu time in seconds
-u The maximum number of processes available to a single user
-v The maximum amount of virtual memory available to the shell
-x The maximum number of file locks
从这里可以看出,如果 -c是显示:core file size (blocks, -c)
如果这个值为0,则无法生成core文件。所以可以使用:
#ulimit -c 1024 或者 #ulimit -c unlimited 来使能 core文件。
如果程序出错时生成Core 文件,则会显示Segmentation fault (core dumped)。
7. Core Dump的核心转储文件目录和命名规则:
/proc/sys/kernel/core_uses_pid可以控制产生的core文件的文件名中是否添加pid作为扩展,如果添加则文件内容为1,否则为0
8.反推应用名字和相关信息
1.ps -ef|grep bpe/hps 看进程的重启时间
[root]# ps -ef|grep hps
root 1966 1 0 Jan19 ? 00:00:00 ./hps
root 1968 1966 0 Jan19 ? 1-11:31:36 ./hps
root 8251 1 0 Jul23 ? 00:00:00 ./hps
root 8253 8251 0 Jul23 ? 02:33:17 ./hps
root 9225 1 0 Mar26 ? 00:00:00 ./hps
root 9227 9225 0 Mar26 ? 16:17:26 ./hps
root 11778 1 0 Mar17 ? 00:00:00 ./hps
root 11780 11778 0 Mar17 ? 10:03:21 ./hps
root 14555 1 0 Jul14 ? 00:00:00 ./hps
root 14557 14555 12 Jul14 ? 3-08:21:30 ./hps
root 17573 1 0 May21 ? 00:00:00 ./hps
root 17575 17573 0 May21 ? 02:35:42 ./hps
root 18754 1 0 Apr02 ? 00:00:00 ./hps
root 18756 18754 0 Apr02 ? 04:33:11 ./hps
root 21221 1 0 Aug06 ? 00:00:00 ./hps
root 21223 21221 14 Aug06 ? 13:39:10 ./hps
root 24987 1 0 13:45 pts/1 00:00:00 ./hps
root 24989 24987 12 13:45 pts/1 00:06:55 ./hps
root 27844 20840 0 14:40 pts/3 00:00:00 grep hps
root 31568 1 0 Apr09 ? 00:00:00 ./hps
root 31570 31568 1 Apr09 ? 1-17:20:24 ./hps
2.通过进程号 ll /proc/ 查看应用
[root]# ll /proc/24987
total 0
dr-xr-xr-x 2 root root 0 Aug 10 14:12 attr
-r-------- 1 root root 0 Aug 10 14:12 auxv
-r--r--r-- 1 root root 0 Aug 10 13:45 cmdline
-rw-r--r-- 1 root root 0 Aug 10 14:12 coredump_filter
-r--r--r-- 1 root root 0 Aug 10 14:12 cpuset
lrwxrwxrwx 1 root root 0 Aug 10 14:12 cwd -> /opt/app/hps4gauth
-r-------- 1 root root 0 Aug 10 14:12 environ
lrwxrwxrwx 1 root root 0 Aug 10 14:12 exe -> /opt/app/hps4gauth/hps
dr-x------ 2 root root 0 Aug 10 13:45 fd
dr-x------ 2 root root 0 Aug 10 14:12 fdinfo
-r-------- 1 root root 0 Aug 10 14:12 io
-r--r--r-- 1 root root 0 Aug 10 14:12 limits
-rw-r--r-- 1 root root 0 Aug 10 14:12 loginuid
-r--r--r-- 1 root root 0 Aug 10 14:12 maps
-rw------- 1 root root 0 Aug 10 14:12 mem
-r--r--r-- 1 root root 0 Aug 10 13:45 mounts
-r-------- 1 root root 0 Aug 10 14:12 mountstats
-r--r--r-- 1 root root 0 Aug 10 14:12 numa_maps
-rw-r--r-- 1 root root 0 Aug 10 14:12 oom_adj
-r--r--r-- 1 root root 0 Aug 10 14:12 oom_score
lrwxrwxrwx 1 root root 0 Aug 10 14:12 root -> /
-r--r--r-- 1 root root 0 Aug 10 14:12 schedstat
-r--r--r-- 1 root root 0 Aug 10 14:12 smaps
-r--r--r-- 1 root root 0 Aug 10 13:45 stat
-r--r--r-- 1 root root 0 Aug 10 13:46 statm
-r--r--r-- 1 root root 0 Aug 10 13:45 status
dr-xr-xr-x 3 root root 0 Aug 10 14:12 task
-r--r--r-- 1 root root 0 Aug 10 14:12 wchan
这估计是所能找到的最好的方法了…………。
原文链接:http://www.cnblogs.com/dongzhiquan/archive/2012/01/20/2328355.html
(转)Linux core 文件介绍与处理的更多相关文章
- Linux core 文件介绍
Linux core 文件介绍 http://www.cnblogs.com/dongzhiquan/archive/2012/01/20/2328355.html 1. core文件的简单介绍在一个 ...
- linux core文件设置
http://blog.csdn.net/ctthuangcheng/article/details/8963551 linux core文件设置 分类: Linux OS Debugging Te ...
- 【转】 Linux Core Dump 介绍
=============================================================== Linux core dump的祥细介绍和使用 =========== ...
- core文件介绍
原文链接:http://team.eyou.com/?p=27 如有侵犯您的版权,请联系windeal12@qq.com linux下,产生core文件,和不产生core文件的条件: 当我们的程序崩溃 ...
- linux core文件机制
在程序不寻常退出时,内核会在当前工作目录下生成一个core文件(是一个内存映像,同时加上调试信息).使用gdb来查看core文件,可以指示出导致程序出错的代码所在文件和行数. 1.core文件的生成开 ...
- Linux core 文件浅析
浅析Linux下core文件 当我们的程序崩溃时,内核有可能把该程序当前内存映射到core文件里,方便程序员找到程序出现问题的地方.最常出 现的,几乎所有C程序员都出现过的错误就是"段错误& ...
- Linux core 文件 gdb
http://blog.csdn.net/mr_chenping/article/details/13767609 在程序不寻常退出时,内核会在当前工作目录下生成一个core文件(是一个内存映像,同时 ...
- linux core文件的打开和分析
1. core文件生成打开方式: ulimit -c unlimited echo "1" > /proc/sys/kernel/core_uses_pid 看下服务器上是否 ...
- 鸟哥笔记:linux系统日志文件介绍
简单的说日志文件就是记录系统活动信息的几个文件,例如:何时.何地(来源ip).何人(什么服务名称).做了什么操作.换句话说就是:记录系统在什么时候由哪个进程做了什么样的行为时,发生了什么事件等. 日志 ...
随机推荐
- jquery实现显示和隐藏toggle()方法的使用
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...
- Windows编程坐标系统概念
Windows编程中关于设置映象模式的四个函数 SetWindowOrgSetViewPortOrgSetMapModeSetWindowExtExSetViewPortExtEx 一.Windows ...
- RAID分类
1. RAID在数据库存储上的应用 随着单块磁盘在数据安全.性能.容量上呈现出的局限,磁盘阵列(Redundant Arrays of Inexpensive/Independent Disks, ...
- Ajax封装函数笔记
Ajax封装函数: function ajax(method, url, data, success) { //打开浏览器 //1.创建一个ajax对象 var xhr = null; try { x ...
- JMeter使用简单教程
去Apache JMeter官网下载最新的Windows下的zip安装包并解压 进入JMeter安装目录下的bin目录,双击jmeter.bat,运行JMeter程序 打开测试计划主界 ...
- 推荐几款主流的Css Reset
1.Eric Meyer’s “Reset CSS”(重置的很极端) 官方网址:CSS Tools: Reset CSS 2.HTML5 Doctor CSS Reset 官方网址:HTML5 Res ...
- javascipt : reduce
$scope.totalPrice = function () { return $scope.addcartProduct.reduce(function (money, product) { re ...
- Kindle电子阅读器收不到个人文档推送解决方案
最近我的 kindle 固件版本更新到 5.8.7.0.1 ,发现增加了生字注音功能,瞬间变成小学生阅读神器有木有,不过,这个功能可以隐藏.显示,看着碍眼隐藏即可,还可以减少和增加生字注音.感觉对于经 ...
- Java设计模式之《单例模式》及应用场景
摘要: 原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6510196.html 所谓单例,指的就是单实例,有且仅有一个类实例,这个单例不应该 ...
- maven lean install 的时候出错 Failed to clean project
问题解决1 : 这种情况是属于 本地有多个 java 线程,关掉其中不用的,或者 都关闭就可以了. 问题解决 2 : Caused by: org.springframework.beans.f ...