linux 系统资源限制查看

Posted sz_bb

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux 系统资源限制查看相关的知识,希望对你有一定的参考价值。

#include <stdio.h>
#include "errno.h"
#include <sys/resource.h>


/*
struct rlimit
rlim_t rlim_cur;  //软限制
rlim_t rlim_max;  //硬限制

*/


//int getrlimit(int resource, struct rlimit *rlim);
//int setrlimit(int resource, const struct rlimit *rlim);


int main(int argc, void *argv[])
struct rlimit rlimit_;
rlimit_.rlim_cur = 0;
rlimit_.rlim_max = 0;

//进程虚拟内存总量限制
if (getrlimit(RLIMIT_AS, &rlimit_) == -1)
printf("errno=%d\\n",errno);
return -1;

printf("RLIMIT_AS cur=%d, mac=%d\\n", rlimit_.rlim_cur, rlimit_.rlim_max);


//进程核心转储文件(core dump)大小限制
if (getrlimit(RLIMIT_CORE, &rlimit_) == -1)
printf("errno=%d\\n",errno);
return -1;

printf("RLIMIT_CORE cur=%d, mac=%d\\n", rlimit_.rlim_cur, rlimit_.rlim_max);


//进程CPU时间限制 单位(秒)
if (getrlimit(RLIMIT_CPU, &rlimit_) == -1)
printf("errno=%d\\n",errno);
return -1;

printf("RLIMIT_CPU cur=%d, mac=%d\\n", rlimit_.rlim_cur, rlimit_.rlim_max);

//文件大小限制,单位(字节)
if (getrlimit(RLIMIT_FSIZE, &rlimit_) == -1)
printf("errno=%d\\n",errno);
return -1;

printf("RLIMIT_FSIZE cur=%d, mac=%d\\n", rlimit_.rlim_cur, rlimit_.rlim_max);

//进程数据段限制,单位(字节)
if (getrlimit(RLIMIT_DATA, &rlimit_) == -1)
printf("errno=%d\\n",errno);
return -1;

printf("RLIMIT_DATA cur=%d, mac=%d\\n", rlimit_.rlim_cur, rlimit_.rlim_max);


//文件描述符数量限制
if (getrlimit(RLIMIT_NOFILE, &rlimit_) == -1)
printf("errno=%d\\n",errno);
return -1;

printf("RLIMIT_NOFILE cur=%d, mac=%d\\n", rlimit_.rlim_cur, rlimit_.rlim_max);


//用户创建进程数量限制
if (getrlimit(RLIMIT_NPROC, &rlimit_) == -1)
printf("errno=%d\\n",errno);
return -1;

printf("RLIMIT_NPROC cur=%d, mac=%d\\n", rlimit_.rlim_cur, rlimit_.rlim_max);


//进程能挂起的信号数量限制
if (getrlimit(RLIMIT_SIGPENDING, &rlimit_) == -1)
printf("errno=%d\\n",errno);
return -1;

printf("RLIMIT_SIGPENDING cur=%d, mac=%d\\n", rlimit_.rlim_cur, rlimit_.rlim_max);



//进程栈限制
if (getrlimit(RLIMIT_STACK, &rlimit_) == -1)
printf("errno=%d\\n",errno);
return -1;

printf("RLIMIT_STACK cur=%d, mac=%d\\n", rlimit_.rlim_cur, rlimit_.rlim_max);

return 0;


输出内容:

RLIMIT_AS cur=-1, mac=-1
RLIMIT_CORE cur=0, mac=-1
RLIMIT_CPU cur=-1, mac=-1
RLIMIT_FSIZE cur=-1, mac=-1
RLIMIT_DATA cur=-1, mac=-1
RLIMIT_NOFILE cur=1024, mac=4096
RLIMIT_NPROC cur=1024, mac=14733
RLIMIT_SIGPENDING cur=14733, mac=14733
RLIMIT_STACK cur=10485760, mac=-1

以上是关于linux 系统资源限制查看的主要内容,如果未能解决你的问题,请参考以下文章

查看和解除Linux系统对用户使用资源的限制

如何灵活运用Linux 进程资源监控和进程限制

如何灵活运用Linux 进程资源监控和进程限制

如何灵活运用Linux 进程资源监控和进程限制

linux系统怎样下载迅雷的资源

Linux 进程资源用量监控和按用户设置进程限制