In /proc/<PID>/limits every limit has two columns: Soft Limit and Hard Limit.
The soft limit is the one in force right now: that is where a process gets EMFILE. The hard limit is the ceiling for the soft one. A process raises its own soft limit by itself, but no higher than the hard one. The hard limit it can only lower; raising it takes root — and even root cannot go above the fs.nr_open kernel parameter.
Your shell has different values for the two:
The soft one is 1024, the hard one is hundreds of times larger. Programs that need many files raise their soft limit to the hard one by themselves at start. The shipper has 64 for both, so it has nowhere to go.
ulimit -n 4096 without an option changes both limits at once, and that shell can no longer raise the hard one back. ulimit -Sn 4096 changes only the soft one.
Your shell's soft limit is 1024. You typed ulimit -Hn 2048 and then ulimit -Hn 4096. What will the shell print for the second command?
-
The shell prints Invalid argument when the hard limit is set below the soft one. 4096 is above the soft 1024; the refusal here is about the right to raise the hard limit.
-
Any process can lower its hard limit, but raising it takes root. After
ulimit -Hn 2048, raising it to 4096 is refused.
A process can lower its own hard limit but cannot raise it back; without root the second command gets Operation not permitted. Try it in a separate shell so you do not touch your own: bash -c 'ulimit -Hn 2048; ulimit -Hn 4096'.
Key points
- The soft limit is in force now; the hard limit is the ceiling for the soft one.
- A process raises its soft limit by itself up to the hard one; only root raises the hard one.
-
ulimit -nwith a number changes both limits,ulimit -Snonly the soft one.