I've figured it out.
On some kernels (e.g. 2.6.32+), at least on CentOS/RHEL, you can change the resource limits of a running process using /proc/<pid>/limits
, e.g.:
$ grep "open files" /proc/23052/limits
Limit Soft Limit Hard Limit Units
Max open files 1024 4096 files
To change the maximum open files to a soft limit of 4096, hard limit of 8192:
echo -n "Max open files=4096:8192" > /proc/23052/limits
This gives:
$ grep "open files" /proc/23052/limits
Limit Soft Limit Hard Limit Units
Max open files 4096 8192 files
Note the -n
in echo -n
- without that, you'll get an "invalid argument
" error.
The above doesn't always work, so
Another option is prlimit
command, introduced with util-linux 2.21
allows you to read and change the limits of running processes.
This is a followup to the writable /proc/<pid>/limits
, which was not integrated in mainline kernel. This solution should work.
$ prlimit --nofile --output RESOURCE,SOFT,HARD --pid 23052
RESOURCE SOFT HARD
NOFILE 1024 4096
Set the limits:
$ prlimit --nofile=4096:8192 --pid 23052
Confirm:
$ prlimit --nofile --output RESOURCE,SOFT,HARD --pid 23052RESOURCE SOFT HARD
NOFILE 4096 8192
$ grep "open files" /proc/23052/limits
Limit Soft Limit Hard Limit Units
Max open files 4096 8192 files
prlimt
can also be used:prlimit --nofile=<soft>:<hard>