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

    默认不会生成 控制台运行 ulimit -c unlimited 就生成了,只对该控制台有效

    • 测试代码
    #include <stdio.h>
    const char *str = "test";
    void core_test(){
    int *p=0;
    *p=1;
    }
     
    int main(){
        core_test();
        return 0;
    }
    • 运行
    gcc -g test.c -o test
    ulimit -c 1024 默认是0来的
    gdb core test
     
     
     
    • ulimit -a
    core file size          (blocks, -c) 0
    data seg size           (kbytes, -d) unlimited
    scheduling priority             (-e) 20
    file size               (blocks, -f) unlimited
    pending signals                 (-i) 16382
    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) unlimited
    virtual memory          (kbytes, -v) unlimited
    file locks                      (-x) unlimited
     
     
    • 修改core的格式
    echo "core-%e-%p-%t" > /proc/sys/kernel/core_pattern
    以下是参数列表:
        %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 添加命令名
    •  查看core dump
    gdb --core=core.12345(core dump文件名) 或 gdb exe名 core名
    bt              查看程序运行到哪儿,backtrace
    file exe名   找exe位置
    l                列出代码
    where       显示在哪儿down掉
     
     
    注意:有些情况下,使用了seteuid或setegid,改变了进城了用户和组,比如,无论谁运行mysql,mysql都以mysql用户运行。这种情况下,默认系统不会做core dump,需要把/proc/sys/fs/suid_dumpable内容改成1来要求系统生成core dump 
    • 生成core 

    kill -s SIGSEGV  PID 或者 gdb -p pid (gdb)执行命令gcore filename

     当程序接收到以下UNIX信号会产生core文件:

    名字

    说明

    ANSI C  POSIX.1

    SVR4  4.3+BSD

    缺省动作

    SIGABRT

    异常终止(abort)

      .       .

      .      .

    终止w/core

    SIGBUS

    硬件故障

              .

      .      .

    终止w/core

    SIGEMT

    硬件故障

     

      .      .

    终止w/core

    SIGFPE

    算术异常

      .       .

      .      .

    终止w/core

    SIGILL

    非法硬件指令

      .       .

      .      .

    终止w/core

    SIGIOT

    硬件故障

     

      .      .

    终止w/core

    SIGQUIT

    终端退出符

              .

      .      .

    终止w/core

    SIGSEGV

    无效存储访问

      .       .

      .      .

    终止w/core

    SIGSYS

    无效系统调用

     

      .      .

    终止w/core

    SIGTRAP

    硬件故障

     

      .      .

    终止w/core

    SIGXCPU

    超过CPU限制(setrlimit)

     

      .      .

    终止w/core

    SIGXFSZ

    超过文件长度限制(setrlimit)

     

      .      .

    终止w/core

     
     
  • 相关阅读:
    第1课 Git、谁与争锋
    程序员最真实的10个瞬间
    程序员最真实的10个瞬间
    一文读懂前端缓存
    一文读懂前端缓存
    一文读懂前端缓存
    EF使用CodeFirst创建数据库和表
    EF使用CodeFirst创建数据库和表
    EF使用CodeFirst创建数据库和表
    ASP.NET MVC的过滤器笔记
  • 原文地址:https://www.cnblogs.com/ahuo/p/2606475.html
Copyright © 2011-2022 走看看