Created
November 10, 2012 07:16
-
-
Save shinaisan/4050281 to your computer and use it in GitHub Desktop.
getrlimit sample.
This file contains hidden or 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
/* -*- mode: c; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8-unix -*- */ | |
#include <stdio.h> | |
#include <stdint.h> | |
#include <sys/resource.h> | |
void print_rlimit(struct rlimit *r, const char *name) { | |
int64_t cur; /* Soft limit */ | |
int64_t max; /* Hard limit */ | |
cur = r->rlim_cur; | |
max = r->rlim_max; | |
printf("RLIMIT_%s :rlim_cur => %#llx, :rlim_max => %#llx¥n", | |
name, cur, max); | |
} | |
int main(int argc, char *argv[]) { | |
struct rlimit rlim; | |
int resources[] = {RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA, RLIMIT_FSIZE, | |
RLIMIT_MEMLOCK, RLIMIT_NOFILE, RLIMIT_NPROC, RLIMIT_RSS, | |
RLIMIT_STACK}; | |
const char *names[] = {"CORE", "CPU", "DATA", "FSIZE", | |
"MEMLOCK", "NOFILE", "NPROC", "RSS", | |
"STACK"}; | |
int n = sizeof(resources)/sizeof(resources[0]); | |
int i; | |
for (i = 0; i < n; i++) { | |
getrlimit(resources[i], &rlim); | |
print_rlimit(&rlim, names[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just if someone needs it (like me), I have done some refactoring, removed issues that causes warnings, removed 64 bit machine restriction.
https://gist.github.com/xdevelnet/f6f4293f136003dae25bb41f127e0b5d