-
-
Save xdevelnet/f6f4293f136003dae25bb41f127e0b5d to your computer and use it in GitHub Desktop.
getrlimit sample.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/resource.h> | |
#define RLIMIT(a) {#a, RLIMIT_##a} | |
struct {char *s; int resnum;} r[] = { | |
RLIMIT(CORE), RLIMIT(CPU), RLIMIT(DATA), RLIMIT(FSIZE), RLIMIT(MEMLOCK), RLIMIT(NOFILE), | |
RLIMIT(NPROC), RLIMIT(RSS), RLIMIT(STACK) | |
}; | |
void print_rlimit(struct rlimit *r, const char *name) { | |
size_t cur = r->rlim_cur; // Soft limit | |
size_t max = r->rlim_max; // Hard limit | |
printf("RLIMIT_%s :rlim_cur => %zu, :rlim_max => %zu\n", name, cur, max); | |
} | |
int main() { | |
size_t i = 0; | |
while(i < sizeof(r)/sizeof(r[0])) { | |
struct rlimit rlim; | |
getrlimit(r[i].resnum, &rlim); | |
print_rlimit(&rlim, r[i++].s); | |
} | |
return EXIT_SUCCESS; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
cc --std=c99 -Wall -Werror getrlimit.c -o getrlimit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment