How do I check the ulimit for another user and change open files?

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

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

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.


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