[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to set permanent ulimit



On 2010-01-26 at 12:54:49 -0500, Vadkan Jozsef wrote:
> How can I set ulimit?
> when I give:
> 
> ulimit -n 10240
> 
> ok, 
> 
> ulimit -n
> 
> gives 10240. But. after a few minutes, it 1024 again!
> How can I set the ulimit to be permanently 10240?
> It would be important! :S
> Thank you :\

   man bash
   /ulimit

Description for the -n option says

   The maximum number of open file descriptors (most systems do not allow this value to be set)

Apparently, one must be root to set ulimit.  I tried it as a non-root user and got

   -bash: ulimit: open files: cannot modify limit: Operation not permitted

But as the root user it works.  I don't know how long you waited, but so far, my changes
are holding.  I'm running bash version 3.2-4 under Lenny.  However, the change holds only
for the current shell session and shell sessions descended from it.  Other shell sessions
are not affected.  The following will not work:

$ su
Password: [enter password for root]
# ulimit -n 10240
# ulimit -n
10240
# exit
$ ulimit -n
1024

The su command invokes a new shell.  You change the limit in the new shell.
The exit command takes you back to the previous shell.  The limit in that
shell is unchanged.  If you did something like this:

[login as fred]
$ su
Password: [enter password for root]
# ulimit -n 10240
# su fred
$ ulimit -n
10240

Then a non-root user (fred) gets the new value for ulimit.
The first shell is the login shell.  It's limit is still 1024.
The second (nested) shell is the root shell entered by "su" with no
arguments.  It's limit starts as 1024 but is dynamically changed to 10240.
The "su fred" command invokes a third nested shell, which
inherits its ulimit value from the second nested shell.
It's limit is 10240.  But this requires a couple of nested
shells, the second of which is still running as root, which
is a security exposure.  All the user has to do is type "exit"
and he is now root!  Maybe someone else knows a better way.


Reply to: