免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3153 | 回复: 5
打印 上一主题 下一主题

无法产生coredump [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-02-23 15:13 |只看该作者 |倒序浏览
请专家帮忙看看为啥我的程序崩溃了以后不能产生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

代码如下

  1. #include <stdio.h>
  2. #include <signal.h>
  3. #define INPUTLEN 100

  4. main()
  5. {
  6.                 struct sigaction newhandler;
  7.                 sigset_t blocked;
  8.                 void inthandler();
  9.                 void intsignalaction(int s, siginfo_t * pinof, void * p);
  10.                 char x[INPUTLEN];
  11.                 char readback=0;
  12.                 *((int *)0) = 0;
  13.                 printf("1 to use sa_handler\n2 to use sa_sigaction(default)\nyou input:");
  14.                 readback = getchar();
  15.                 if(readback == '1')
  16.                 {
  17.                         printf("use SA_RESETHAND | SA_RESTART\n");
  18.                         newhandler.sa_flags = SA_RESETHAND | SA_RESTART;
  19.                 }
  20.                 else
  21.                 {
  22.                         printf("n = %x%c\n",readback,readback);
  23.                         printf("use SA_RESETHAND | SA_RESTART | SA_SIGINFO\n");
  24.                         newhandler.sa_flags = SA_RESETHAND | SA_RESTART | SA_SIGINFO;
  25.                 }
  26.                 /* load these two members first */
  27. //                newhandler.sa_handler = inthandler;
  28.                 newhandler.sa_sigaction = intsignalaction;
  29.                 sigemptyset(&blocked);
  30.                 sigaddset(&blocked, SIGQUIT);
  31.                 newhandler.sa_mask = blocked;
  32.                 printf("newhandler.sa_flags=%x\n", newhandler.sa_flags);
  33.                 if(sigaction(SIGINT, &newhandler, NULL) == -1)
  34.                         perror("sigaction");
  35.                 else
  36.                         while(1){
  37.                                         fgets(x, INPUTLEN, stdin);
  38.                                         printf("main loop input: %s",x);
  39.                         }       
  40. }

  41. void inthandler(int s)
  42. {
  43.                 printf("inthandler Called with signal %d\n",s);
  44.                 sleep(s);
  45.                 printf("done handling signal %d\n",s);
  46. }


  47. #if 0
  48.    siginfo_t {
  49.                   int      si_signo;  /* Signal number */
  50.                   int      si_errno;  /* An errno value */
  51.                   int      si_code;   /* Signal code */
  52.                   pid_t    si_pid;    /* Sending process ID */
  53.                   uid_t    si_uid;    /* Real user ID of sending process */
  54.                   int      si_status; /* Exit value or signal */
  55.                   clock_t  si_utime;  /* User time consumed */
  56.                   clock_t  si_stime;  /* System time consumed */
  57.                   sigval_t si_value;  /* Signal value */
  58.                   int      si_int;    /* POSIX.1b signal */
  59.                   void *   si_ptr;    /* POSIX.1b signal */
  60.                   void *   si_addr;   /* Memory location which caused fault */
  61.                   int      si_band;   /* Band event */
  62.                   int      si_fd;     /* File descriptor */
  63.               }
  64. #endif

  65. void siginfo_t_dump(siginfo_t * pinof)
  66. {
  67.     printf("si_signo = %d\n", pinof->si_signo);
  68. //    printf("si_errno = %d\n", pinof->si_errno);
  69. /*    printf("si_code = %d\n", pinof->si_code);
  70.     printf("si_pid = %d\n", pinof->si_pid);
  71.     printf("si_uid = %d\n", pinof->si_uid);
  72.     printf("si_status = %d\n", pinof->si_status);
  73.     printf("si_utime = %d\n", pinof->si_utime);
  74.     printf("si_stime = %d\n", pinof->si_stime);
  75.     printf("si_value = %d\n", pinof->si_value);
  76.     printf("si_int = %d\n", pinof->si_int);
  77.     printf("si_ptr = %d\n", pinof->si_ptr);
  78.     printf("si_addr = %d\n", pinof->si_addr);
  79.     printf("si_band = %d\n", pinof->si_band);
  80.     printf("si_fd = %d\n", pinof->si_fd);
  81. */
  82. }



  83. void intsignalaction(int s, siginfo_t * pinof, void * p)
  84. {
  85.                 printf("intsignalaction Called with signal %d\n",s);
  86.                 siginfo_t_dump(pinof);
  87.                 sleep(2);
  88.                 printf("done handling signal %d\n",s);
  89. }

复制代码
编译,执行结果如下
cc  -g -O0 -l pthread sigactdemo.c
[root@localhost testcode]# ./a.out
Segmentation fault

但是在/opt目录下找不到core_xxxx文件
请问还有什么需要配置的吗?

论坛徽章:
0
2 [报告]
发表于 2010-02-23 15:52 |只看该作者
ulimit -a看一眼

论坛徽章:
0
3 [报告]
发表于 2010-02-23 17:55 |只看该作者
ulimit -a看一眼
liying_gg 发表于 2010-02-23 15:52

ulimit 已经设置成ulimited了

    [root@localhost testcode]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 16128
max locked memory       (kbytes, -l) 32
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) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16128
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

论坛徽章:
0
4 [报告]
发表于 2010-02-24 13:06 |只看该作者
ulimit -c unlimited试一试

论坛徽章:
0
5 [报告]
发表于 2010-02-24 14:14 |只看该作者
ulimit 已经设置成ulimited了

    [root@localhost testcode]# ulimit -a
core file size          ( ...
顽石菜 发表于 2010-02-23 17:55



ulimit -a 里面的
core file size          (blocks, -c) 0
项表示core文件的限制大小,目前为0.

修改了就可以了。

论坛徽章:
0
6 [报告]
发表于 2010-02-25 15:45 |只看该作者
回复 5# zerix
啊,果然是这样的。
谢谢!
被那个unlimited给迷惑了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP