Last active
December 12, 2015 07:58
-
-
Save hjr3/4740788 to your computer and use it in GitHub Desktop.
How does setrlimit work when the value is 0?
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
/* | |
* | |
* gcc -o rlimit rlimit.c | |
*/ | |
#include <sys/resource.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
#include <string.h> | |
int main(int argv, char *argc[]) | |
{ | |
struct rlimit r; | |
int rv; | |
r.rlim_max = r.rlim_cur = 0; | |
if (setrlimit(RLIMIT_NOFILE, &r) != 0) { | |
printf("setrlimit() failed with errno=%d, %s\n", errno, strerror(errno)); | |
exit(1); | |
} | |
if (getrlimit(RLIMIT_NOFILE, &r) != 0) { | |
printf("getrlimit() failed with errno=%d, %s\n", errno, strerror(errno)); | |
exit(1); | |
} | |
printf("The soft limit is %llu\n", r.rlim_cur); | |
printf("The hard limit is %llu\n", r.rlim_max); | |
if (open("./rlimit.c", O_RDONLY)) { | |
printf("open() failed with errno=%d, %s\n", errno, strerror(errno)); | |
exit(1); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment