Skip to content

Instantly share code, notes, and snippets.

@adembo
Created August 11, 2017 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adembo/fba94e3956a8db4ad45d3fce91106c6b to your computer and use it in GitHub Desktop.
Save adembo/fba94e3956a8db4ad45d3fce91106c6b to your computer and use it in GitHub Desktop.
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/resource.h>
#include <time.h>
int main(int argc, char* argv[]) {
struct rlimit lim;
int ret = getrlimit(RLIMIT_NOFILE, &lim);
if (ret == -1) {
perror("getrlimit");
return 1;
}
srand(time(NULL));
lim.rlim_cur = (rand() % 100) + 1;
printf("Setting RLIMIT_NOFILE soft limit to %lu\n", lim.rlim_cur);
ret = setrlimit(RLIMIT_NOFILE, &lim);
if (ret == -1) {
perror("setrlimit");
return 1;
}
int i;
for (i = 0;; i++) {
ret = open("/dev/null", O_RDONLY);
if (ret == -1) {
perror("open");
break;
}
}
printf("Opened %d fds\n", i);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment