How to generate a core dump in Linux on a segmentation fault?

前端 未结 12 1233
余生分开走
余生分开走 2020-11-22 17:06

I have a process in Linux that\'s getting a segmentation fault. How can I tell it to generate a core dump when it fails?

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 17:40

    Better to turn on core dump programmatically using system call setrlimit.

    example:

    #include 
    
    bool enable_core_dump(){    
        struct rlimit corelim;
    
        corelim.rlim_cur = RLIM_INFINITY;
        corelim.rlim_max = RLIM_INFINITY;
    
        return (0 == setrlimit(RLIMIT_CORE, &corelim));
    }
    

提交回复
热议问题