Q:

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:

echo "100000" > /proc/sys/fs/file-max
ulimit -n 100000
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?

A:

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.

