I plan to run a Java app using nohup ... &. The limit must apply to commands like this.

migrated from stackoverflow.com Apr 5 '11 at 8:28

This question came from our site for professional and enthusiast programmers.

  • But this caused an error in my java program – bruce dou Mar 8 '10 at 8:53

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

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 1024 – bruce dou Mar 8 '10 at 8:51
  • No need to reboot. Just run sysctl fs.file-max=123456. (/etc/sysctl.conf is read at boot time by a script that calls sysctl on the contents.) – Gilles Apr 5 '11 at 21:06
ulimit -n

can modify per process settings and


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 1024 – bruce dou Mar 8 '10 at 8:47

You can use ulimit for this:


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.

  • 1
    I want to connect to lots of clients – bruce dou Mar 8 '10 at 8:52

vi ~/.bashrc And add a line at the end of file

ulimit -n 169203

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy