- 论坛徽章:
- 0
|
请专家帮忙看看为啥我的程序崩溃了以后不能产生coredump?
配置如下:
[root@localhost ~]# ulimit
ulimited
[root@localhost ~]# cat /proc/sys/kernel/core_pattern
/opt/core-%e-%p-%t
core_pattern core_uses_pid
[root@localhost ~]# cat /proc/sys/kernel/core_uses_pid
1
代码如下
- #include <stdio.h>
- #include <signal.h>
- #define INPUTLEN 100
- main()
- {
- struct sigaction newhandler;
- sigset_t blocked;
- void inthandler();
- void intsignalaction(int s, siginfo_t * pinof, void * p);
- char x[INPUTLEN];
- char readback=0;
- *((int *)0) = 0;
- printf("1 to use sa_handler\n2 to use sa_sigaction(default)\nyou input:");
- readback = getchar();
- if(readback == '1')
- {
- printf("use SA_RESETHAND | SA_RESTART\n");
- newhandler.sa_flags = SA_RESETHAND | SA_RESTART;
- }
- else
- {
- printf("n = %x%c\n",readback,readback);
- printf("use SA_RESETHAND | SA_RESTART | SA_SIGINFO\n");
- newhandler.sa_flags = SA_RESETHAND | SA_RESTART | SA_SIGINFO;
- }
- /* load these two members first */
- // newhandler.sa_handler = inthandler;
- newhandler.sa_sigaction = intsignalaction;
- sigemptyset(&blocked);
- sigaddset(&blocked, SIGQUIT);
- newhandler.sa_mask = blocked;
- printf("newhandler.sa_flags=%x\n", newhandler.sa_flags);
- if(sigaction(SIGINT, &newhandler, NULL) == -1)
- perror("sigaction");
- else
- while(1){
- fgets(x, INPUTLEN, stdin);
- printf("main loop input: %s",x);
- }
- }
- void inthandler(int s)
- {
- printf("inthandler Called with signal %d\n",s);
- sleep(s);
- printf("done handling signal %d\n",s);
- }
- #if 0
- siginfo_t {
- int si_signo; /* Signal number */
- int si_errno; /* An errno value */
- int si_code; /* Signal code */
- pid_t si_pid; /* Sending process ID */
- uid_t si_uid; /* Real user ID of sending process */
- int si_status; /* Exit value or signal */
- clock_t si_utime; /* User time consumed */
- clock_t si_stime; /* System time consumed */
- sigval_t si_value; /* Signal value */
- int si_int; /* POSIX.1b signal */
- void * si_ptr; /* POSIX.1b signal */
- void * si_addr; /* Memory location which caused fault */
- int si_band; /* Band event */
- int si_fd; /* File descriptor */
- }
- #endif
- void siginfo_t_dump(siginfo_t * pinof)
- {
- printf("si_signo = %d\n", pinof->si_signo);
- // printf("si_errno = %d\n", pinof->si_errno);
- /* printf("si_code = %d\n", pinof->si_code);
- printf("si_pid = %d\n", pinof->si_pid);
- printf("si_uid = %d\n", pinof->si_uid);
- printf("si_status = %d\n", pinof->si_status);
- printf("si_utime = %d\n", pinof->si_utime);
- printf("si_stime = %d\n", pinof->si_stime);
- printf("si_value = %d\n", pinof->si_value);
- printf("si_int = %d\n", pinof->si_int);
- printf("si_ptr = %d\n", pinof->si_ptr);
- printf("si_addr = %d\n", pinof->si_addr);
- printf("si_band = %d\n", pinof->si_band);
- printf("si_fd = %d\n", pinof->si_fd);
- */
- }
- void intsignalaction(int s, siginfo_t * pinof, void * p)
- {
- printf("intsignalaction Called with signal %d\n",s);
- siginfo_t_dump(pinof);
- sleep(2);
- printf("done handling signal %d\n",s);
- }
复制代码 编译,执行结果如下
cc -g -O0 -l pthread sigactdemo.c
[root@localhost testcode]# ./a.out
Segmentation fault
但是在/opt目录下找不到core_xxxx文件
请问还有什么需要配置的吗? |
|