core文件大小,进程能打开的文件数大小的设置
2011-12-27 00:08
351 查看
相关链接: http://blog.csdn.net/yuyin86/article/details/8014840
Core dump在服务器上的应用
// corefile.c
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//#include<sys/wait.h>
// 设置core文件大小,进程能打开的文件数大小的函数
int SetRLimit()
{
#ifdef WIN32
#else
struct rlimit tRLimit;
int iRtn = 0;
printf("SetRLimit ...\n");
// 设置core文件大小
iRtn = getrlimit(RLIMIT_CORE, &tRLimit);
if(0 == iRtn)
{
printf("getrlimit corefile size limit_cur = %d, max = %d\n", tRLimit.rlim_cur, tRLimit.rlim_max);
tRLimit.rlim_max =RLIM_INFINITY;//设置最大限制为无限
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;
}
运行:
ulimit -c //查看系统默认core文件大小,如果为0,不会生产core文件
ulimit -c unlimited //设置core文件的大小为不限大小
gcc -g corefile.c -o corefile //记得加 -g ,不然没有行号,是一个地址值,看不出什么来
gdb ./corefile core //用gdb运行产生的core文件
bt //查看出问题的堆栈
Core dump在服务器上的应用
// corefile.c
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//#include<sys/wait.h>
// 设置core文件大小,进程能打开的文件数大小的函数
int SetRLimit()
{
#ifdef WIN32
#else
struct rlimit tRLimit;
int iRtn = 0;
printf("SetRLimit ...\n");
// 设置core文件大小
iRtn = getrlimit(RLIMIT_CORE, &tRLimit);
if(0 == iRtn)
{
printf("getrlimit corefile size limit_cur = %d, max = %d\n", tRLimit.rlim_cur, tRLimit.rlim_max);
tRLimit.rlim_max =RLIM_INFINITY;//设置最大限制为无限
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;
}
运行:
ulimit -c //查看系统默认core文件大小,如果为0,不会生产core文件
ulimit -c unlimited //设置core文件的大小为不限大小
gcc -g corefile.c -o corefile //记得加 -g ,不然没有行号,是一个地址值,看不出什么来
gdb ./corefile core //用gdb运行产生的core文件
bt //查看出问题的堆栈
相关文章推荐
- LInux 设置 单个进程打开最大的文件数
- Linux 设置“进程最大可打开的文件数”永久有效的方式
- linux永久打开core文件设置
- 设置Windows下的Core文件输出(监控异常进程)
- 设置Linux最大打开文件数和进程数
- PHP文件上传大小设置
- 利用core文件对多线程和多进程进行调试
- 设置Win10文件资源管理器默认打开“这台电脑”
- 您试图打开以前版本的Microsoft Office创建的文件。注册表策略设置已阻止此文件在该版本中打开的解决办法
- 进程异常退出core文件
- linux下进程的最大线程数、进程最大数、进程打开的文件数
- MyEclipse 之 jsp、js、java、xml文件字体大小设置
- Unix/Linux产生core文件的调试和core文件大小限制的修改
- 如何验证linux进程打开文件数的默认最大值(通常是1024)? 知识点: ulimit; watch -n 1 'ls -l /proc/xxx/fd | wc -l'
- linux下如何查看某个进程打开了那些文件
- wordpress设置上传文件大小
- mysql查询进程、导入数据包大小设置
- linux下进程的最大线程数、进程最大数、进程打开的文件数
- [PHP学习]Wampserver上传文件大小设置
- 设置上传文件的最大大小