"Max open files" for working process
echo -n "Max open files=20:20" > /proc/$pid/limits
...works in RHEL5.5 and RHEL6.7.
Note that the "-n" is mandatory; a trailing newline will generate a complaint about invalid arguments.
Another option is to use the prlimit command (from the util-linux package). For example if you want to set the maximum number of open files for a running process to 4096:
prlimit -n4096 -p pid_of_process
You could use gdb, break into the process, call the aforementioned syscalls to raise the limit you're interested in, then continue the job and exit gdb. I've edited things on the fly this way a few times.
Your app wouldn't be down, but just frozen for the moment while you performed the call. if you're quick (or you script it!), it'll likely not be noticeable.
As a system administrator: The /etc/security/limits.conf
file controls this on most Linux installations; it allows you to set per-user limits. You'll want a line like myuser - nofile 1000
.
Within a process: The getrlimit and setrlimit calls control most per-process resource allocation limits. RLIMIT_NOFILE
controls the maximum number of file descriptors. You will need appropriate permissions to call it.