歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux生成Core_file機制

Linux生成Core_file機制

日期:2017/3/1 10:44:53   编辑:Linux編程

#include<stdio.h>

// 產生core文件函數
int SetRLimit()
{
#ifdef WIN32
#else
struct rlimt tRLimit;
int iRtn = 0;
printf("SetRLimit ...\n");
iRtn = getrlimit(RLIMIT_CORE, &tRLimt);
if(0 == iRtn)
{
printf("getrlimit corefile size limit_cur = %d, max = %d\n", tRLimit.rlimit.rlim_cur, tRLimit.rlim_max);
tRLimit.rlim_max = tRLimit.rlim_cur = RLIM_INFINITY;
iRtn = setrlimit(RLIMIT_CORE, &tRLimit);
printf("setrlimit corefile size limit:cur = %d, return %d\n", tRLimit.rlim_cur, iRtn);
}
iRtn = getrlimit(RLIMIT_NOFILE, &tRLimit);
if(0 == iRtn)
{
printf("getrlimit number of files limit : cur = %d, max = %d\n", tRLimit.rlim_cur, tRLimit.rlim_max);
tRLimit.rlim_cur = 10000;
iRtn = setrlimit(RLIMIT_NOFILE, &tRLimit);
printf("setrlimit number of files limit : cur = %d, return %d\n",tRLimit.rlim_cur, iRtn);
}
#endif
return 0;
}

int mian()
{
unsigned char *ptr = 0x00;
SetRLimit();
*ptr =0x00; //會產生段錯誤,測試生產core文件
return 0;
}

Copyright © Linux教程網 All Rights Reserved