According to the kernel documentation, /proc/sys/fs/file-max
is the maximum, total, global number of file handles the kernel will allocate before choking. This is the kernel's limit, not your current user's. So you can open 590432, provided you're alone on an idle system (single-user mode, no daemons running). File handles (struct file
in the kernel) are different from file descriptors: multiple file descriptors can point to the same file handle, and file handles can also exist without an associated descriptor internally. No system-wide file descriptor limit is set; this can only be mandated per process.
Note that the documentation is out of date: the file has been /proc/sys/fs/file-max
for a long time. Thanks to Martin Jambon for pointing this out.
The difference between soft and hard limits is answered here, on SE. You can raise or lower a soft limit as an ordinary user, provided you don't overstep the hard limit. You can also lower a hard limit (but you can't raise it again for that process). As the superuser, you can raise and lower both hard and soft limits. The dual limit scheme is used to enforce system policies, but also allow ordinary users to set temporary limits for themselves and later change them.
Note that if you try to lower a hard limit below the soft limit (and you're not the superuser), you'll get EINVAL
back (Invalid Argument).
So, in your particular case, ulimit
(which is the same as ulimit -Sf
) says you don't have a soft limit on the size of files written by the shell and its subprocesses. (that's probably a good idea in most cases)
Your other invocation, ulimit -Hn
reports on the -n
limit (maximum number of open file descriptors), not the -f
limit, which is why the soft limit seems higher than the hard limit. If you enter ulimit -Hf
you'll also get unlimited
.
ulimit -Hn
target the very limit of the system to allocated file descriptor capabilities ? – DiaJos Sep 19 '18 at 11:27ulimit
only affects the limits for the current process.The limits of the current process are bequeathed to children processes too, but each process has a separate count. E.g. with
– Alexios Sep 26 '18 at 06:55ulimit -Hn 10
, you can only have 10 file descriptors open at any one time. Each child process you create can only have up to 10 file descriptors too. Only the superuser may increase a limit once set. If you set one too low, your only option may be to kill your shell process and start a new one.