Search code examples
linuxfilesocketsulimitsysctl

What is the most correct way to set limits of number of files on Linux?


There are 3 ways to set limits of number of files and sockets on Linux:

  1. echo "100000" > /proc/sys/fs/file-max
  2. ulimit -n 100000
  3. sysctl -w fs.file-max=100000

What is the difference?

What is the most correct way to set limits of number of files on Linux?


Solution

  • sysctl is an interface for writing to /proc/sys and so does the same as echoing directly to the files. Whereas sysctl applies across the whole filesystem, ulimit only applies to writes from the shell and processes started by the shell.