当前位置: 首页 > java >正文

Core文件作用、设置及用法

1.Core文件简介

Core文件其实就是内存的映像,当程序崩溃时,存储内存的相应信息,主用用于对程序进行调试。当程序崩溃时便会产生core文件,其实准确的应该说是core dump 文件,默认生成位置与可执行程序位于同一目录下,文件名为core.***,其中***是某一数字。

2.开启或关闭Core文件的生成

关闭或阻止core文件生成:

$ulimit -c 0

打开core文件生成:

$ulimit -c unlimited

检查core文件的选项是否打开:

$ulimit -a

ulimit参数含义如下: 

             -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

以上配置只对当前会话起作用,下次重新登陆后,还是得重新配置。要想配置永久生效,得在/etc/profile或者/etc/security/limits.conf文件中进行配置。

首先以root权限登陆,然后打开/etc/security/limits.conf文件,进行配置:

#vim /etc/security/limits.conf

<domain>    <type>    <item>        <value>

       *              soft          core         unlimited

或者在/etc/profile中作如下配置:

#vim /etc/profile

ulimit -S -c unlimited >/dev/null 2>&1

或者想配置只针对某一用户有效,则修改此用户的~/.bashrc或者~/.bash_profile文件:

limit -c unlimited

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   (-c指定core文件)
它会启动GNU的调试器,来调试core文件,并且会显示生成此core文件的程序名,中止此程序的信号等等
如果你已经知道是由什么程序生成此core文件的,比如MyServer崩溃了生成core.12345,那么用此指令调试:
gdb -c core MyServer


5. 一个小方法来测试产生core文件

直接输入指令:
kill -s SIGSEGV $$

参考网址: http://yehubilee.blog.51cto.com/1373999/1078777
                  http://en.wikipedia.org/wiki/Core_dump
     http://www.ibm.com/developerworks/cn/linux/l-cn-ulimit/

http://www.xdnf.cn/news/11508.html

相关文章:

  • 阿里制造:“犸良”一站式动效制作平台
  • 著名的 P=NP 问题到底是什么?
  • 【Java.Web】JSP —— 语法基础 —— 包含include
  • 如何制作个人网站(如何搭建个人博客)
  • python汇率编程_利用Python中的Xpath实现一个在线汇率转换器
  • 城市轨道交通信号系统学习笔记1--ATC系统概述
  • 模拟摄像机的的“线”与数字相机中的“像素”的关系
  • 中小型企业(公司)网络规划
  • 国内外开源sns源码大全
  • 迅时MX8(FXO)8口语音网关连接Elastix+服务器配置
  • 时间复杂度和空间复杂度详解
  • 点滴收集-Editplus V3/UE V15工具及其它信息(花维 音乐网址)
  • java layout_java layout种类和用途。要详细
  • blog转移
  • HTML学生个人网站作业设计:HTML做一个公司官网首页页面(纯html代码)
  • 空间参考系相关概念
  • 2022起重机司机(限门式起重机)试题及模拟考试
  • GB2312汉字拼音对照表
  • 32位操作系统在哪里下载java_微信32位版本官方下载-微信32位手机版下载 v7.0.20 安卓版...
  • 大一python期末简答题,大一python题库及答案
  • 4.1svn安装与使用
  • 理解Linux内核空间与用户空间
  • seaborn中的色板02详解
  • 仙五前补充资料
  • 2015届互联网名企校招网址一览表
  • 有刷QQ会员和7砖的软件?
  • 关于WEBQQ的实现(一)
  • 一条命令轻松解决 「应用程序 “xxx” 不能打开」的问题
  • 信息检索:搜索引擎---怎样量化评价搜索引擎的结果质量
  • 剑灵南天国服务器位置,剑灵南天国实验室申请地址_剑灵南天国实验室申请资格答案_游戏堡...