ubuntu生成&设置core文件,调试段错误_ubuntu生成core文件-CSDN博客
ubuntu设置core文件_ubuntu core文件默认位置-CSDN博客
ulimit -a
sudo vim /etc/profile #或者 vi ~/.bashrc
ulimit -c unlimited #添加, 退出
source /etc/profile
sudo systemctl disable apport.service
vi /etc/sysctl.conf #add
kernel.core_uses_pid = 1
#kernel.core_pattern = /corefile/core-%e-%p-%t
kernel.core_pattern=core-%e-%p-%t
sysctl -p
/proc/sys/kernel/core_pattern #查看core文件位置.
编写代码
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
void segv_handler(int signo)
{
printf("in segv_handler\n");
while (signo) {
sleep(1);
}
}
int main(int argc, char *argv[])
{
char *pointer = NULL;
signal(SIGSEGV, segv_handler);
*pointer = 'c';
return 0;
}
验证