Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is 1048577 the limit of open files in Ubuntu? If I try the following code it works.

However, if I change the value to 1048578 the setrlimit function will return the code 1 and errno will be set to 1 as well.

int l;
struct rlimit rl;

rl.rlim_cur = 1048577;
rl.rlim_max = 1048577;

l = setrlimit(RLIMIT_NOFILE, &rl);

if(l != 0){
    errx(1, "setrlimit returned result %d", errno);

I am running it as root and compiling with GCC 4.6.3

share|improve this question
up vote 3 down vote accepted

You've hit the kernel maximum (NR_OPEN), see

cat /proc/sys/fs/nr_open
share|improve this answer
So if I change this file and reboot it I got a new maximum? – Frederico Schardong Mar 2 '13 at 19:30
I just tried and it doesn't work this simple. – Frederico Schardong Mar 2 '13 at 19:41
I think you would have to recompile the kernel ;( Can you tell me why you need to have so many open files per process? – arrange Mar 2 '13 at 22:19
It's the way my application works, I am changing it to have at maximum 65536 files or maybe less. As far as I tested 65536 is ok. – Frederico Schardong Mar 3 '13 at 21:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.