refactor: make resource limits function

main
Sean McBride 5 years ago
parent b5e9abced5
commit 565a03db5d

@ -32,7 +32,6 @@ get_time()
return (Tp.tv_sec * 1000000 + Tp.tv_usec);
}
static void
usage(char *cmd)
{
@ -40,6 +39,30 @@ usage(char *cmd)
debuglog("%s <modules_file>\n", cmd);
}
// Sets the process data segment (RLIMIT_DATA) and # file descriptors
// (RLIMIT_NOFILE) soft limit to its hard limit (see man getrlimit)
void set_resource_limits_to_max(){
struct rlimit resource_limit;
if (getrlimit(RLIMIT_DATA, &resource_limit) < 0) {
perror("getrlimit RLIMIT_DATA");
exit(-1);
}
resource_limit.rlim_cur = resource_limit.rlim_max;
if (setrlimit(RLIMIT_DATA, &resource_limit) < 0) {
perror("setrlimit RLIMIT_DATA");
exit(-1);
}
if (getrlimit(RLIMIT_NOFILE, &resource_limit) < 0) {
perror("getrlimit RLIMIT_NOFILE");
exit(-1);
}
resource_limit.rlim_cur = resource_limit.rlim_max;
if (setrlimit(RLIMIT_NOFILE, &resource_limit) < 0) {
perror("setrlimit RLIMIT_NOFILE");
exit(-1);
}
}
int
main(int argc, char **argv)
{
@ -57,27 +80,7 @@ main(int argc, char **argv)
exit(-1);
}
// Sets the process data segment (RLIMIT_DATA) and # file descriptors
// (RLIMIT_NOFILE) soft limit to its hard limit (see man getrlimit)
struct rlimit r;
if (getrlimit(RLIMIT_DATA, &r) < 0) {
perror("getrlimit RLIMIT_DATA");
exit(-1);
}
r.rlim_cur = r.rlim_max;
if (setrlimit(RLIMIT_DATA, &r) < 0) {
perror("setrlimit RLIMIT_DATA");
exit(-1);
}
if (getrlimit(RLIMIT_NOFILE, &r) < 0) {
perror("getrlimit RLIMIT_NOFILE");
exit(-1);
}
r.rlim_cur = r.rlim_max;
if (setrlimit(RLIMIT_NOFILE, &r) < 0) {
perror("setrlimit RLIMIT_NOFILE");
exit(-1);
}
set_resource_limits_to_max();
// Find the number of processors currently online
ncores = sysconf(_SC_NPROCESSORS_ONLN);

Loading…
Cancel
Save