Welcome 微信登录

首页 / 操作系统 / Linux / Linux生成Core_file机制

#include<stdio.h>// 产生core文件函数
int SetRLimit()
{
#ifdef WIN32
#else
 struct rlimt tRLimit;
 int iRtn = 0;
 printf("SetRLimit ... ");
 iRtn = getrlimit(RLIMIT_CORE, &tRLimt);
 if(0 == iRtn)
 {
  printf("getrlimit corefile size limit_cur = %d, max = %d ", 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 ", tRLimit.rlim_cur, iRtn);
 }
 iRtn = getrlimit(RLIMIT_NOFILE, &tRLimit);
 if(0 == iRtn)
 {
  printf("getrlimit number of files limit : cur = %d, max = %d ", 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 ",tRLimit.rlim_cur, iRtn);
 }
#endif
 return 0;
}int mian()
{
 unsigned char *ptr = 0x00;
 SetRLimit();
 *ptr =0x00;  //会产生段错误,测试生产core文件
 return 0;
}