Skip to content

Instantly share code, notes, and snippets.

@shinaisan
Created November 10, 2012 07:16
Show Gist options
  • Save shinaisan/4050281 to your computer and use it in GitHub Desktop.
Save shinaisan/4050281 to your computer and use it in GitHub Desktop.
getrlimit sample.
/* -*- 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;
}
@xdevelnet
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment