0

I am trying to increase the max open files for an application but my attempts have been unsuccessful. The hard limit is being set appropriately, but the soft limit is staying as the default 1024.

Under /etc/init.d/[application], under the start() function I have these two lines before any other commands are executed:

ulimit -Sn 64512 2> /dev/null
ulimit -Hn 80896 2> /dev/null

But when I check the limits under /proc/[pid]/limits, the hard limit is 80896 but the soft limit is 1024.

Since the application is ran as root, I added a new .conf file under /etc/security/limits.d/ with the following entries:

root    soft    nofile    64512
root    hard    nofile    80896

But there is no change in /proc/[pid]/limits.

How do I set max open files limits permanently for a specific application?

I'm testing in RHEL 6.10

  • ulimit is for limiting the resource of a user. you better create a new user and change the ulimits for that user and run your application with it. – binarysta May 18 at 15:29
  • That doesn't really answer my question? Why can't I do the same thing with root? Is there a reason why I shouldn't be able to change the soft limits of root versus a non-root user? – AnthonyBB May 18 at 15:36
  • you should be able but I just wanted to clarify ulimit is not for a process or application, its a limit for user. – binarysta May 18 at 15:38
0

After reading some of the arguments of user vs. process of ulimit (here) and @binarysta comments, and reading the ulimit man page over and over, I realized that my init.d approached would work, but I was doing it in the wrong order. Hard limit is the absolute maximum a user can increase it own soft limit, therefore setting the soft limit first would be ignored if this is greater than the hard limit at time of execution.

Therefore instead of doing this:

root    soft    nofile    64512
root    hard    nofile    80896

You have to do this:

root    hard    nofile    80896
root    soft    nofile    64512

Proving once again, order matters.

Therefore /etc/init.d/[application]:

start() {
ulimit -Hn 80896 2> /dev/null
ulimit -Sn 64512 2> /dev/null
[rest of start function]
}

restart() {
# only if restart() function does not call start()
ulimit -Hn 80896 2> /dev/null
ulimit -Sn 64512 2> /dev/null
[rest of restart function]
}

Leaving this question/answer in case other people run into the same issue.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.