-int create_dump(int pair)
-{
- // Try to enable core dumps
- struct rlimit core_limit;
- core_limit.rlim_cur = RLIM_INFINITY;
- core_limit.rlim_max = RLIM_INFINITY;
-
- if(setrlimit(RLIMIT_CORE, &core_limit) < 0)
- fprintf(stderr, "setrlimit: %s\nWarning: core dumps may be truncated or non-existant\n", strerror(errno));
-
- int status;
- switch(fork()){
- case 0:
- // We are the child process -- run the actual program
- xbt_abort();
- break;
-
- case -1:
- // An error occurred, shouldn't happen
- perror("fork");
- return -1;
-
- default:
- // We are the parent process -- wait for the child process to exit
- if(wait(&status) < 0)
- perror("wait");
- if(WIFSIGNALED(status) && WCOREDUMP(status)){
- char *core_name = xbt_malloc(20);
- sprintf(core_name,"core_%d", pair);
- rename("core", core_name);
- free(core_name);
- }
- }