#include <stdio.h> #include <sys/resource.h> int main() { struct rlimit rlim; if(getrlimit(RLIMIT_MEMLOCK, &rlim) == -1) { fprintf(stderr, "getrlimit error."); return -1; } if(rlim.rlim_cur == RLIM_INFINITY) printf("infinite"); else printf("soft: %lld\n", (long long)rlim.rlim_cur); if(rlim.rlim_max == RLIM_INFINITY) printf("infinite"); else printf("hard: %lld\n", (long long)rlim.rlim_max); return 0; }
每个进程都用一组资源限制值,它们可以用来限制进程能够消耗的各种系统资源。如在执行任意一个程序前如果不想让它消耗太多资源,
则可以设置该进程的资源限制。使用shell的内置命令ulimit可以设置shell的资源限制。