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
You've hit the kernel maximum (NR_OPEN), see