20

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: 
$

3 Answers 3

31

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
1
  • 2
    This should be the accepted answer, used it to find out the current ulimit for the redis user on Debian.
    – tholu
    Apr 13, 2016 at 13:11
8

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.

3
  • 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, 2014 at 7:04
  • 12
    This is how you check more /proc/<proc_id>/limits ...maybe worth adding to answer
    – Tony
    Sep 17, 2014 at 4:33
  • 5
    Worth mentioning the location of limits.conf too: /etc/security/limits.conf
    – UpTheCreek
    Nov 4, 2014 at 13:43
2

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

1
  • 8
    This won't work if <USERNAME> is unable to login (has the nologin shell).
    – dr_
    May 28, 2019 at 8:34

You must log in to answer this question.

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