Created
August 11, 2017 20:38
-
-
Save adembo/fba94e3956a8db4ad45d3fce91106c6b to your computer and use it in GitHub Desktop.
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 <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