I plan to run a Java app using nohup ... &. The limit must apply to commands like this.
6 Answers
Most systems use PAM, and have the pam_limits module set limits based on /etc/security/limits.conf. The per-user limit for open files is called nofile. You can set it for every user or for a particular user or group, and you can set a limit that the user can override (soft limit) and another that only root can override (hard limit). The documentation and the limits.conf man page have the details. For example, to raise the limit to 50000 for everyone, put this line in /etc/limits.conf (the setting takes effect when you log in):
* - nofile 50000
-
within
limits.confdo* hard nofile 50000and/or* soft nofile 50000. I don't know the technical difference between hard and soft and have always done both.ron– ron2020-03-02 18:39:37 +00:00Commented Mar 2, 2020 at 18:39 -
within SLES 11.4 using tcsh for example, one can do
limit descriptors 50000to change the value within the given terminal window/session.ron– ron2020-03-02 18:41:41 +00:00Commented Mar 2, 2020 at 18:41 -
@ron -` in the second column sets both the soft and the hard limit. You only need to set them separately if you want different values. A soft limit can be changed at any time by running the
ulimitcommand (calledlimitin csh). An unprivileged user can never go higher than the hard limit.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2020-03-03 22:22:36 +00:00Commented Mar 3, 2020 at 22:22 -
if i only set the hard, does the soft value remain the default? if I only set soft and not hard, does hard remain default value or inherently equal soft value? Can I set soft > hard? The soft is the real value that is in effect? sorry for the questions.ron– ron2020-03-04 14:14:50 +00:00Commented Mar 4, 2020 at 14:14
-
@ron The soft limit is automatically capped at the hard limit. If you only set the hard limit, then this sets the soft limit to max(default_soft_limit, actual_hard_limit).Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2020-03-04 17:22:23 +00:00Commented Mar 4, 2020 at 17:22
you can add fs.file-max = <your number> into /etc/sysctl.conf. Then reboot.
-
cat /proc/sys/fs/file-max is 169203,but ulimit -n is 1024bruce dou– bruce dou2010-03-08 08:51:45 +00:00Commented Mar 8, 2010 at 8:51
-
No need to reboot. Just run
sysctl fs.file-max=123456. (/etc/sysctl.confis read at boot time by a script that callssysctlon the contents.)Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2011-04-05 21:06:56 +00:00Commented Apr 5, 2011 at 21:06
ulimit -n
can modify per process settings and
/proc/sys/fs/file-max
or the sysctl variable called fs.file-max can be used to read and set the system-wide value
-
cat /proc/sys/fs/file-max is 169203,but ulimit -n is 1024bruce dou– bruce dou2010-03-08 08:47:18 +00:00Commented Mar 8, 2010 at 8:47
You can use ulimit for this:
http://bloggerdigest.blogspot.com/2006/10/purpose-of-ulimit-linux-command.html
Although you should make sure that opening so many file handles is absolutely necessary before resorting to such adjustments. Increasing the maximum file handles just because you have forgotten to do an inputstream.close() in a loop is only going to delay the underlying problem.
-
1I want to connect to lots of clientsbruce dou– bruce dou2010-03-08 08:52:50 +00:00Commented Mar 8, 2010 at 8:52
Use ulimit(Bash command - man bash or find similar for your shell) per program instance. Do not use global system limits if you don't know what are you doing - possible DoS.
-
In SLES 11.4 I have set
nofileinlimits.confto be 100000 successfully. I can attest that setting too large a value prevented subsequent log in with SSH and I had to boot from dvd to correct that value in limits.conf to recover the system.ron– ron2020-03-02 18:45:24 +00:00Commented Mar 2, 2020 at 18:45