Skip to content

Instantly share code, notes, and snippets.

@Flushot
Last active April 23, 2019 05:04
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 Flushot/7bef7d69668ee9a54e447163e0d62e74 to your computer and use it in GitHub Desktop.
Save Flushot/7bef7d69668ee9a54e447163e0d62e74 to your computer and use it in GitHub Desktop.
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "usage: %s [pid]", argv[0]);
return 1;
}
pid_t pid = atoi(argv[1]);
struct rlimit new_limit, old_limit;
// Max open files
new_limit.rlim_cur = 100000; // Soft
new_limit.rlim_max = 500000; // Hard
int ret = prlimit(pid, RLIMIT_NOFILE, &new_limit, &old_limit);
if (ret == 0) {
printf("Changed %i nofile limit from %u/%u to %u/%u\n", pid,
old_limit.rlim_cur, old_limit.rlim_max,
new_limit.rlim_cur, new_limit.rlim_max);
} else {
perror("prlimit");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment