I wrote a small program that opens a bunch of files and played with open files limit on Ubuntu(as root). I was surprised to see that only user-level limits had effect on max number of files open.

I added this in /etc/security/limits.conf:

root hard nofile 30000
root soft nofile 30000

And set /proc/sys/fs/file-max to 20000 (sysctl -w fs.file-max=20000).

I then ran my program to open 29000 files without any problems.

Why does not system-level setting have any effect in this case?

  • Have you restarted/started a new session after modifying limits.conf ? – BatchyX May 17 '13 at 14:05
  • @BatchyX Yep, I did – snovo May 17 '13 at 14:40

I figured it out, to recap -

user-level limits on Linux are set in /etc/security/limits.conf (or under /limits.d dir)

system-level limits are set in /etc/sysctl.conf (immediately changed by a command like this: sysctl -w fs.file-max=20000)

In my initial test system-level limit of open files was ignored because I was running my program as root , so it was a privileged process and privileged processes on Linux bypass all kernel permission checks (http://linux.die.net/man/7/capabilities)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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