线程非法退出,如何产生core文件

bcb_alone 2007-01-10 11:29:41
linux9.0 + gcc3.2.2
代码如下:
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void *thread(void* m)
{
char *bb = NULL;
memcpy(bb,"fdsafaf",4);
}

main()
{
pthread_t t;
pthread_attr_t at;
int ret;
int i;
i = 1;
ret = pthread_create(&t,NULL,thread,&i);
if(ret!=0)
{
printf ("Create pthread error!n");
exit (1);
}


while(1){
printf("run\n");
sleep(10);
}
}

程序运行。会退出。但不会产生core文件。
g++ -lpthread -g thread.cpp -o thread.
但如果
char *bb = NULL;
memcpy(bb,"fdsafaf",4);
放在主程序中,是可以产生的。(已经ulimit -c 100000了)
是不是还要什么编译选项啊!
谢谢啊!
...全文
281 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
darkone 2007-01-11
  • 打赏
  • 举报
回复
linux是用进程模拟来实现线程的,所以你的线程其实就是子进程,而你的主进程并没有出错,所以产生不了CORE文件
bcb_alone 2007-01-10
  • 打赏
  • 举报
回复
没要知道?
adream99 2007-01-10
  • 打赏
  • 举报
回复
在shell中执行
ulimit -c unlimited
就可以了
adream99 2007-01-10
  • 打赏
  • 举报
回复
void *thread(void* m)
{
char *bb = NULL;
memcpy(bb,"fdsafaf",4);
}
bb没有申请空间!!肯定出错!

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧