“Max open files” for working process

2019-01-11 03:52发布

问题:

Is it possible to increase "Max open files" parameter for working process ? I mean this parameter:

cat /proc/<pid>/limits | grep files

Thanks for your advices

回答1:

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.



回答2:

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

prlimit -n4096 -p pid_of_process



回答3:

Old thread, I know.

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.



回答4:

Yes, it is possible to increase the limits in /proc/<pid>/limits at run time. Just find the pid and execute below command:

echo -n "Max open files=20:20" > /proc/$pid/limits


回答5:

This link details how to change this system wide or per user.

Many application such as Oracle database or Apache web server needs this range quite higher. So you can increase the maximum number of open files by setting a new value in kernel variable /proc/sys/fs/file-max as follows (login as the root):

$ sysctl -w fs.file-max=100000

You need to edit /etc/sysctl.conf file and put following line so that after reboot the setting will remain as it is



回答6:

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.



回答7:

The following commands give the max # of open files per process permissible by default limits (soft and hard respectively):

ulimit -Sa
ulimit -Ha

You can use a program or a command to change these limits. Look at ulimit (man ulimit).