zoukankan      html  css  js  c++  java
  • linux c: core dump

    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.

  • 相关阅读:
    vs2015+opencv3.3.1 +Eigen 3.3.4 c++实现 薄膜插值 泊松图像编辑(v=0||Δf=0)
    vs2015+opencv3.3.1 实现 c++ 双边滤波器(Bilateral Filter)
    vs2015+opencv3.3.1 实现 c++ 彩色高斯滤波器(Gaussian Smoothing, Gaussian Blur, Gaussian Filter)
    vs2015+opencv3.3.1 实现 c++ 灰度高斯滤波器
    vs2015+opencv3.3.1 实现 c++ 直方图均衡化
    函数形参为基类数组,实参为继承类数组,下存在的问题------c++程序设计原理与实践(进阶篇)
    函数返回值string与返回值bool区别------c++程序设计原理与实践(进阶篇)
    (c++11)随机数------c++程序设计原理与实践(进阶篇)
    实现求解线性方程(矩阵、高斯消去法)------c++程序设计原理与实践(进阶篇)
    Centos ATI 显卡安装,“LCD 信号超出范围” 解决方法
  • 原文地址:https://www.cnblogs.com/mylinux/p/4959367.html
Copyright © 2011-2022 走看看