title: How to do the equivalent of "ulimit -n 400" from within C?
body: <p>I must run the command "ulimit -n 400" to raise number of allowed open files before I start my program written in C, but is there a way to do the equivalent from within the C program?</p>
  
  <p>That is, increase the number of allowed open file descriptors for that process. (I am not interested in per thread limits.)</p>
  
  <p>Will it involve setting ulimits, then forking a child which will be allowed to have more open files?</p>
  
  <p>Of course, I could write a shell wrapper which runs ulimit, then start my C program, but it feels less elegant. I could also grep through the source code of bash or sh to see how it is done there - maybe I will if I get no answer here.</p>
  
  <p>Also related, if you want to select on a lot of file descriptors, <a href="https://stackoverflow.com/questions/848717/handling-more-than-1024-file-descriptors-in-c-on-linux">look here</a>.</p>