1. core dump文件系统设置 http://www.cnblogs.com/no7dw/archive/2013/02/18/2915819.html

编译时需要输入-g才会生成coredump文件:

gcc -g -o test test.c

core文件的生成开关和大小限制:

1)使用ulimit -c 命令可查看core文件的生成开关。若结果为0,则表示关闭了此功能,不会生成core文件。

2)使用ulimit -c filesize命令,可以限制core文件的大小

  ulimit -c unlimited不限制core文件大小

如何使用Core文件:
  在Linux下,使用:
  #gdb -c core.pid program_name
  就可以进入gdb模式。
  输入where,就可以指出是在哪一行被Down掉,哪个function内,由谁调用等等。
  (gdb) where
  或者输入 bt。
  (gdb) bt

  pstack 也可以查看coredump文件;

2. Coredump产生的原因和几种情况 http://blog.chinaunix.net/uid-20671208-id-4910096.html

一般进程产生coredump是因为进程收到了一个segmentfault的信号,这时候,进程就会coredump,这个信号为SIGSEGV,一般在程序中看到的是收到11号信号。其就是SIGSEGV信号。比如:

其产生的几种可能有:

2.1 内存访问越界

a) 数组下标访问越界,当然也包括STL中的容器下标访问越界。

b) 遍历字符串时,依靠字符串结束符来判断字符串是否结束,但是字符串没有正常的使用结束符。

c) 使用strcpy, strcat, sprintf, strcmp,strcasecmp等字符串操作函数,将目标字符串写越界。应该使用strncpy, strlcpy, strncat, strlcat, snprintf, strncmp, strncasecmp等函数防止读写越界。

2.2 多线程程序使用了线程不安全的函数。

应该使用下面这线程安全入的函数,它们很容易被用错:asctime_r(3c) gethostbyname_r(3n) getservbyname_r(3n)ctermid_r(3s) gethostent_r(3n) getservbyport_r(3n) ctime_r(3c) getlogin_r(3c)getservent_r(3n) fgetgrent_r(3c) getnetbyaddr_r(3n) getspent_r(3c)fgetpwent_r(3c) getnetbyname_r(3n) getspnam_r(3c) fgetspent_r(3c)getnetent_r(3n) gmtime_r(3c) gamma_r(3m) getnetgrent_r(3n) lgamma_r(3m) getauclassent_r(3)getprotobyname_r(3n) localtime_r(3c) getauclassnam_r(3) etprotobynumber_r(3n)nis_sperror_r(3n) getauevent_r(3) getprotoent_r(3n) rand_r(3c) getauevnam_r(3)getpwent_r(3c) readdir_r(3c) getauevnum_r(3) getpwnam_r(3c) strtok_r(3c) getgrent_r(3c)getpwuid_r(3c) tmpnam_r(3s) getgrgid_r(3c) getrpcbyname_r(3n) ttyname_r(3c)getgrnam_r(3c) getrpcbynumber_r(3n) gethostbyaddr_r(3n) getrpcent_r(3n),网络上一个线程安全函数列表的文档。

2.3 多线程读写的变量数据未加锁保护。比如说,全局变量, 静态变量等。

对于会被多个线程同时访问的全局数据,应该注意加锁保护,否则很容易造成coredump

2.4 非法指针,包括空指针,不合法的指针转换,野指针,还有跨平台产品中的结构体字节对齐问题等。

2.5 堆栈溢出。尤其是嵌入式系统,堆栈比较小,很容易就溢出了。

2.6 顺便附带几种不会产生coredump的情况:

The core file will not be generated if

(a)    the process was set-user-ID and the current user is not the owner of the program file, or

(b)     the process was set-group-ID and the current user is not the group owner of the file,

(c)     the user does not have permission to write in the current working directory,

(d)     the file already exists and the user does not have permission to write to it, or

(e)     the file is too big (recall the RLIMIT_CORE limit in Section 7.11). The permissions of the core file (assuming that the file doesn't already exist) are usually user-read and user-write, although Mac OS X sets only user-read.

linux c: core dump的更多相关文章

  1. Linux 设置core dump

    Linux 设置core dump

  2. linux下core dump

    1.前言 一直在从事linux下后台开发,经常与core文件打交道.还记得刚开始从事linux下开发时,程序突然崩溃了,也没有任何日志.我不知所措,同事叫我看看core,我却问什么是core,怎么看. ...

  3. linux下core dump【总结】

    1.前言 一直在从事linux下后台开发,经常与core文件打交道.还记得刚开始从事linux下开发时,程序突然崩溃了,也没有任何日志.我不知所措,同事叫我看看core,我却问什么是core,怎么看. ...

  4. linux中core dump开启使用教程【转】

    转自:http://www.111cn.net/sys/linux/67291.htm 一.什么是coredump 我们经常听到大家说到程序core掉了,需要定位解决,这里说的大部分是指对应程序由于各 ...

  5. 【Linux】Core dump故障分析

    引入: Q:如果一个程序运行3天后才会出错,这个时候难道需要我们一直用GDB调试程序3天吗? A:答案当然是否定的. 我们有更厉害的工具--Core dump 一.Coredump定义 Core Du ...

  6. Linux上Core Dump文件的形成和分析

    原文: http://baidutech.blog.51cto.com/4114344/904419 Core,又称之为Core Dump文件,是Unix/Linux操作系统的一种机制,对于线上服务而 ...

  7. linux (core dump)调试

    转自 http://www.cnblogs.com/hazir/p/linxu_core_dump.html Linux Core Dump 当程序运行的过程中异常终止或崩溃,操作系统会将程序当时的内 ...

  8. linux 平台core dump文件生成

    1. 在终端中输入ulimit -c 如果结果为0,说明当程序崩溃时,系统并不能生成core dump. root@hbg:/# ulimit -c0root@hbg:/# 2.使用ulimit -c ...

  9. Linux 打开core dump功能

    系统打开core dump功能 在终端中输入命令 ulimit -c ,输出的结果为 0,说明默认是关闭 core dump 的,即当程序异常终止时,也不会生成 core dump 文件: 使用命令  ...

随机推荐

  1. HDU_1003Max Sum 简单动归

    以前做过这道题目,那是还不懂状态方程.乱搞一气: #include<cstdio> #include<algorithm> using namespace std; +; in ...

  2. 永久性for循环配合switch语句可以实现菜单功能

    永久性for循环配合switch语句可以实现菜单功能总结:加入想要无条件地跳转到某条语句执行,用goto语句: 加入想要对某种条件进行判断,为真或为假分别执行不同的语句,用if语句 加入想要检测的条件 ...

  3. BZOJ 3401: [Usaco2009 Mar]Look Up 仰望( 单调栈 )

    n <= 105 , 其实是10 ^ 5 ....坑...我一开始写了个模拟结果就 RE 了.. 发现这个后写了个单调栈就 A 了... ---------------------------- ...

  4. javascript面向对象创建高级 Web 应用程序

       目录 JavaScript 对象是词典 JavaScript 函数是最棒的 构造函数而不是类 原型 静态属性和方法 闭包 模拟私有属性 从类继承 模拟命名空间 应当这样编写 JavaScript ...

  5. Codeforces 486B - OR in Matrix

    矩阵的 OR ,也是醉了. 题目意思很简单,就是问你有没有这么一个矩阵,可以变化,得到输入的矩阵. 要求是这个矩阵每行都可以上下任意移动,每列都可以左右任意移动. 解题方法: 1.也是导致我WA 的原 ...

  6. Awesome Delphi

    Awesome Delphi  A curated list of awesome Delphi frameworks, libraries, resources, and shiny things. ...

  7. docker学习笔记16:Dockerfile 指令 ADD 和 COPY介绍

    一.ADD指令 ADD指令的功能是将主机构建环境(上下文)目录中的文件和目录.以及一个URL标记的文件 拷贝到镜像中. 其格式是: ADD  源路径  目标路径 如: #test FROM ubunt ...

  8. zk mysql 主从自动切换

    zookeeper测试: DBI 版本: /DBI-1.616# zjtest7-redis:/root/DBD-mysql-4.031# perl Makefile.PL Can't exec &q ...

  9. WebView.destroy() called while still attached 的解决的方法

    能够如今webView的父组件中删除该webview,然后再Destroy parent.removeView(webView); 然后 webView.removeAllViews(); webVi ...

  10. 对xml进行解析

    1.要解析的xml文件 <?xml version="1.0" encoding="utf-8"?> <infos> <city ...