Command not found when using sudo ulimit

I used ubuntu 12.04 on which I ran ulimit -n, it shows 1024. I want to increase the open file limit from 1024 to 65535, so I tried the following command:

sudo ulimit -n 65535 

but I get the following error:

 sudo: ulimit: command not found 

How to increase the file limit from 1024 to 65535? Any help would be appreciated.

+42
linux shell
Jul 05 '13 at 7:47
source share
2 answers

ulimit is a shell built in as cd , not a standalone program. sudo looking for an executable, but there is no ulimit binary, so you get an error. You need to run it in the shell.

However, although you need to be root in order to increase the limit to 65535, you probably do not want to run your program as root. Therefore, after you raise the limit, you must return to the current user.

To do this, run:

 sudo sh -c "ulimit -n 65535 && exec su $LOGNAME" 

and you will get a new shell without root privileges, but with an increased limit. exec forces the new shell to replace the process with sudo privileges, so after exiting this shell you will not accidentally become root again.

+93
Jul 05 '13 at 8:05
source share

I had to deal with such problems in the past. Since there is no setuid mechanism for shell scripts (because it is unsafe), I found that writing a simple C wrapper using setuid is enough, and then use the system call to change the ulimits of the running process before removing privileges and executing your shell script.

-one
Jul 05 '13 at 8:14
source share



All Articles