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

3
  • 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
    Commented May 18, 2020 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
    Commented May 18, 2020 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
    Commented May 18, 2020 at 15:38

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .