17

I have a process running as the gearman user and I want to change open files to avoid getting this nasty error:

ERROR 2014-09-12 17:49:14.000000 [ main ] accept(Too many open files) -> libgearman-server/gearmand.cc:788

How can I run ulimit as another user on Ubuntu and change open files? I don't currently login as gearman but I do have root access. I tried doing this:

su gearman --shell /bin/bash --command "ulimit -n"

as recommended here but nothing get's output:

$ su gearman --shell /bin/bash --command "ulimit -n"
Password: 
$
22

Revisiting this just because I stumbled across it during a Google search and found Tony's comment to be useful: while it's true that limits are placed at the process level, the way you would determine the limits in place for a particular user would be to find the processes they've started and then check the proc/${id}/limits.

Specifically:

$ ps -u username  # look up processes owned by user
$ sudo grep 'open files' /proc/${id}/limits  # find "Max open files" line for process ID
  • 2
    This should be the accepted answer, used it to find out the current ulimit for the redis user on Debian. – tholu Apr 13 '16 at 13:11
5

When you run the ulimit command it only affects the process that is running ulimit (the shell) and all subprocesses. So when you run bash --command "ulimit -n", it only affects the number of open files for that instance of bash, then bash exits, thus future processes are not affected.

So to accomplish what you want (to increase the open file limit for your real process), it probably makes more sense to edit limits.conf to boost the open file limit for your specific gearman user.

See examples of limits.conf elsewhere or here.

  • That is also what I found but I'd love to be able to check if it "took effect." I don't get the problem I was having anymore so I'm sure it did – Tony Sep 14 '14 at 7:04
  • 9
    This is how you check more /proc/<proc_id>/limits ...maybe worth adding to answer – Tony Sep 17 '14 at 4:33
  • 5
    Worth mentioning the location of limits.conf too: /etc/security/limits.conf – UpTheCreek Nov 4 '14 at 13:43
1

Try using su - <USERNAME> -c ulimit' -Hn'. I just tested it on CEntOS 7, and it works.

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.