<p>When running my application I sometimes get an error about <code>too many files open</code>.</p>

<p>Running <code>ulimit -a</code> reports that the limit is 1024.  How do I increase the limit above 1024?  </p>

<p><strong>Edit</strong>
<code>ulimit -n 2048</code> results in a permission error.</p>

[{'answer_id': 34645, 'author': 'hoyhoy', 'author_id': 3499, 'author_profile': 'https://Stackoverflow.com/users/3499', 'pm_score': 8, 'selected': True, 'text': '<p>You could always try doing a <code>ulimit -n 2048</code>.  This will only reset the limit for your current shell and the number you specify must not exceed the hard limit</p>\n\n<p>Each operating system has a different hard limit setup in a configuration file.  For instance, the hard open file limit on Solaris can be set on boot from /etc/system.</p>\n\n<pre><code>set rlim_fd_max = 166384\nset rlim_fd_cur = 8192\n</code></pre>\n\n<p>On OS X, this same data must be set in /etc/sysctl.conf.</p>\n\n<pre><code>kern.maxfilesperproc=166384\nkern.maxfiles=8192\n</code></pre>\n\n<p>Under Linux, these settings are often in /etc/security/limits.conf.</p>\n\n<p>There are two kinds of limits:</p>\n\n<ul>\n<li><strong>soft</strong> limits are simply the currently enforced limits</li>\n<li><strong>hard</strong> limits mark the maximum value which cannot be exceeded by setting a soft limit</li>\n</ul>\n\n<p>Soft limits could be set by any user while hard limits are changeable only by root.\nLimits are a property of a process. They are inherited when a child process is created so system-wide limits should be set during the system initialization in init scripts and user limits should be set during user login for example by using pam_limits.</p>\n\n<p>There are often defaults set when the machine boots.  So, even though you may reset your ulimit in an individual shell, you may find that it resets back to the previous value on reboot.  You may want to grep your boot scripts for the existence ulimit commands if you want to change the default. </p>\n'}, {'answer_id': 923369, 'author': 'Jonathan Stanton', 'author_id': 5137, 'author_profile': 'https://Stackoverflow.com/users/5137', 'pm_score': 7, 'selected': False, 'text': '<p>If you are using Linux and you got the permission error, you will need to raise the allowed limit in the <code>/etc/limits.conf</code> or <code>/etc/security/limits.conf</code> file (where the file is located depends on your specific Linux distribution). </p>\n\n<p>For example to allow anyone on the machine to raise their number of open files up to 10000 add the line to the <code>limits.conf</code> file. </p>\n\n<p><code>* hard nofile 10000</code></p>\n\n<p>Then logout and relogin to your system and you should be able to do:</p>\n\n<p><code>ulimit -n 10000</code> </p>\n\n<p>without a permission error. </p>\n'}, {'answer_id': 8285278, 'author': 'Vikrant Telkar', 'author_id': 1067805, 'author_profile': 'https://Stackoverflow.com/users/1067805', 'pm_score': 5, 'selected': False, 'text': '<p>1) Add the following line to <code>/etc/security/limits.conf</code></p>\n\n<pre><code>webuser hard nofile 64000\n</code></pre>\n\n<p>then login as webuser</p>\n\n<pre><code>su - webuser\n</code></pre>\n\n<p>2) Edit following two files for webuser</p>\n\n<p>append <strong>.bashrc and .bash_profile</strong> file by running</p>\n\n<pre><code>echo "ulimit -n 64000" &gt;&gt; .bashrc ; echo "ulimit -n 64000" &gt;&gt; .bash_profile\n</code></pre>\n\n<p>3) Log out, then log back in and verify that the changes have been made correctly:</p>\n\n<pre><code>$ ulimit -a | grep open\nopen files                      (-n) 64000\n</code></pre>\n\n<p>Thats it and them boom, boom boom.</p>\n'}, {'answer_id': 9521975, 'author': 'Sysadmin', 'author_id': 1243439, 'author_profile': 'https://Stackoverflow.com/users/1243439', 'pm_score': 3, 'selected': False, 'text': "<p>If some of your services are balking into ulimits, it's sometimes easier to put appropriate commands into service's init-script. For example, when Apache is reporting</p>\n\n<blockquote>\n  <p>[alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread</p>\n</blockquote>\n\n<p>Try to put <code>ulimit -s unlimited</code> into <code>/etc/init.d/httpd</code>. This does not require a server reboot.</p>\n"}]
['https://Stackoverflow.com/questions/34588', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3535/']