Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器 软件资源

软件开发小程序制作系统集成与运维空间租用硬件开发视频监控技术咨询与支持——联系电话:0311-88999002/88999003

首页 / 操作系统 / 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;
}