Linux下产生coredump并压缩保存
一、什么是coredump
我们经常听到大家说到程序core掉了,需要定位解决,这里说的大部分是指对应程序由于各种异常或者bug导致在运行过程中异常退出或者中止,并且在满足一定条件下(这里为什么说需要满足一定的条件呢?下面会分析)会产生一个叫做core的文件。
通常情况下,core文件会包含了程序运行时的内存,寄存器状态,堆栈指针,内存管理信息还有各种函数调用堆栈信息等,我们可以理解为是程序工作当前状态存储生成第一个文件,许多的程序出错的时候都会产生一个core文件,通过工具分析这个文件,我们可以定位到程序异常退出的时候对应的堆栈调用等信息,找出问题所在并进行及时解决。
二、coredump文件的存储位置
core文件默认的存储位置与对应的可执行程序在同一目录下,文件名是core,大家可以通过下面的命令看到core文件的存在位置:
cat /proc/sys/kernel/core_pattern
缺省值是core
三、开启或关闭Core文件的生成
关闭或阻止core文件生成:$ulimit -c 0打开core文件生成:$ulimit -c unlimited检查core文件的选项是否打开:$ulimit -aulimit参数含义如下: -a All current limits are reported-c The maximum size of core files created-d The maximum size of a processdata 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#ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 23125
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 23125
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
以上配置只对当前会话起作用,下次重新登陆后,还是得重新配置。要想配置永久生效,得在/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/profileulimit -S -c unlimited >/dev/null 2>&1
或者想配置只针对某一用户有效,则修改此用户的~/.bashrc或者~/.bash_profile文件:
limit -c unlimited
ulimit -c 0 是禁止产生core文件,而ulimit -c 1024则限制产生的core文件的大小不能超过1024kb
四.设置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
五、压缩coredump
vim /usr/local/sbin/core_helper
#! bin/sh
exec gzip - > /home/panchen/$1-$2-$3-$4.core.gz
echo "|/usr/local/sbin/core_helper" > /proc/sys/kernel/core_pattern
Linux下产生coredump并压缩保存相关推荐
- linux 压缩文件夹格式,Linux下常见文件格式的压缩、解压小结
Linux下常见文件格式的压缩.解压小结 .tar 解包: tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) ...
- 如何在linux下安装rar软件,Linux下安装使用RAR压缩软件的方法
linux下我们常用的压缩软件格式是tar,zip,这里介绍另外一款windows下常用的压缩格式rar文件. 一. 下载RAR for Linux 下载的文件是rarlinux-3.9.b3.tar ...
- 压缩加压 linux 命令,linux下tar加压、压缩命令
linux下tar加压.压缩命令 参数: -c :建立一个压缩文件的参数指令(create 的意思): -x :解开一个压缩文件的参数指令! -t :查看 tarfile 里面的文件! 注意:在参数下 ...
- linux下使用source /etc/profile保存配置后,新的环境变量只能在一个终端里面有效
博客园 首页 新随笔 联系 管理 订阅 <div class="blogStats"><!--done--> 随笔- 6 文章- 2 评论- 2 < ...
- linux系统如何解压rar文件怎么打开,在Linux下如何打开RAR压缩文件
关键词: 在Windows下常见的RAR压缩文件在Linux下目前还没有免费的打开工具. 如果要用,只能用RAR的Linux试用版本. 下载地址是:http://www.rarlab.com/down ...
- 20191004在LINUX下如何将tar压缩文件解压到指定的目录下
百度搜索:tar 解压缩到指定目录 https://zhidao.baidu.com/question/9844116.html 在LINUX下如何将tar压缩文件解压到指定的目录下 各位,请教一下在 ...
- linux 解压rar密码,linux下rar包的压缩与解压方案
方法一: yum install unrar 方法二: 下载地址: 以最新的为准.对于Window下的常见压缩文件.zip和.rar,Linux也有相应的方法来解压它们: 1:对于.zip linux ...
- Linux 下文件打包和压缩
在 Windows 下我们通常会用好压或者是 Winrar 来进行压缩文件,一般没有打包的说法.在 Linux 下却不太一样,我们可以利用一些命令完成对文件的打包和压缩.这篇文章介绍 ta ...
- linux下的打包与压缩
linux压缩或解压缩工具有很多,除了已经很少有人使用的compress外,现在常用的还有tar,bzip2,xz 和gziplinux压缩或解压缩工具有很多,除了已经很少有人使用的compress外 ...
- linux下已修改但尚未保存_Linux下历史命令保存、默认值修改的问题
linux下怎样修改history最大保留数呢? 直接修改配置参数命令为:vi /etc/profile 修改其中"HISTSIZE=1000"参数值即可.如下图: linux历史 ...
最新文章
- Android -- 程序启动画面 Splash
- 微服务架构设计模式 pdf_六种常用的微服务架构设计模式之一: 入门级模式...
- qt之qml开发优缺点_linux配置vlc-qt
- CanalSharp.AspNetCore v0.0.4-支持输出到MongoDB
- java请求注释_求达人给java代码【注释】!!请求尽量详细,万分感谢!!
- java ldap添加用户名密码_java ldap用户密码md5加密
- 1月16日学习内容整理:爬虫框架:Scrapy
- 华为机试HJ60:查找组成一个偶数最接近的两个素数
- 读 《.Net 之美》解析.Net Remoting (应用程序域)-- Part.1
- 用java下载音频文件_喜马拉雅FM下载的音频转换为正常文件的JAVA实现
- TongWeb session超时配置
- ARCGIS基础到INVEST建模
- php呼伦贝尔,呼伦贝尔php培训
- 内存超频时序怎么调_内存时序怎么调
- 工作记录 io流写入linux文件
- QQ “安全检查未通过,禁止下载该文件” 解决方法
- 不能不用也不可乱用的标准化和归一化处理
- Android之页面添加水印
- zookeeper的应用和原理
- 使用js修改图片像素颜色并保存
热门文章
- asp.net Json序列化
- 用微软makecert.exe生成一个自签名的证书
- Gym - 100625G Getting Through 计算几何+并查集
- java循环语句_Java十四天零基础入门-Java for循环语句
- python画龙猫_微信小程序支付demo,后端使用python
- 【快学springboot】2.Restful简介,SpringBoot构建Restful接口
- 大数据项目之dmp用户画像
- 分享几个Python小技巧函数里的4个小花招 1
- 那些做Android开发必须知道的ADB命令
- 总编下午茶:技术老男人的创业经