- 论坛徽章:
- 0
|
最近程序偶尔出一些异常问题,想应用Core Dump文件,开始用简单例子测试是OK的,但做了一个多线程的例子测试时
却发现出现一些奇怪的问题:
1)如果主线程出问题,多数可以记录下core dump文件,但有时候出错之后并不立即退出,并且此时并不产生core dump;
而dmesg总能看到一条新记录产生了。
2)在其它线程中产生异常,多数时候不产生core,但偶尔也产生过几次,还没找到什么规律。
用abort()来产生core dump,结果类似。
难道是Linux对于多线程环境中的core dump支持有问题,或者需要什么额外的配置?
我用的是CentOS 6.2 for x86_64,内核版本2.6.32-220.el6.x86_64。
程序非常简单:- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #define NR_THREADS 64
- // #define CRASH_TID 20
- #define CRASH_TID 65
- void *thread_func(void *arg)
- {
- long id = (long)arg;
- if (id == CRASH_TID)
- {
- printf("Will crash after serveral seconds ...\n");
- // sleep(3);
- sleep(10);
- *(int *)0xffffffffffffffff = 0;
- // abort();
- }
- for ( ; ; )
- {
- sleep(1);
- }
- return NULL;
- }
- int main(int argc, char *argv[])
- {
- int i;
- int ret;
- pthread_t tids[NR_THREADS];
- for (i = 0; i < 64; ++i)
- {
- ret = pthread_create(&tids[i], NULL, thread_func, (void *)(long)i);
- if (ret)
- {
- fprintf(stderr, "Creating thread #%d failed with %d!\n", i, ret);
- exit(2);
- }
- }
- #if CRASH_TID >= NR_THREADS
- printf("Core dump soon ...\n");
- // sleep(1);
- *(int *)0xffffffffffffffff = 0;
- // abort();
- #endif
- for ( ; ; )
- {
- sleep(1);
- }
- return 0;
- }
复制代码 |
|