Cannot change the maximum open files per process with sysctl

懵懂的女人 提交于 2019-12-21 13:15:25

问题


My actual limit is 1024:

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 95979
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

I tried:

sysctl -w fs.file-max=100000

and appending to /etc/sysctl.conf:

fs.file-max = 100000

without success, even after running sysctl -p to reload the settings and/or rebooting, on both Ubuntu 16.04 and CentOS 6.

It always stays set to 1024.


This question is an extension of that other question.


回答1:


For Ubuntu 17.04. See this solution.

Prior to Ubuntu 17.04:

I don't know why the above settings don't work but it seems you can get the same result by using the /etc/security/limits.conf file.

Set the limit in /etc/security/limits.conf

sudo bash -c "echo '* - nofile 10240' >> /etc/security/limits.conf"
  • * means all users. You can replace it by a specific username.
  • - means both soft and hard for the type of limit to be enforced. Hard can only be modified by the superuser. Soft can be modified by a non-root user and cannot be superior to hard.
  • nofile is the Maximum number of open files parameter.
  • 10240 is the new limit.

Reload

Logout and log back in. sudo sysctl -p doesn't seem to be enough to reload.

You can check the new limit with:

ulimit -n

Tested on Ubuntu 16.04 and CentOS 6. Inspired by this answer.




回答2:


For MacOs 10.14.6 and above, the below works if you need to up the limit temporarily:

Check your current limit:

ulimit -n

Mine was 256

Change it:

ulimit -n 1024

Check it again in the same tab:

ulimit -n

Mine now shows 1024.

The change is immediate, no need to log out and in again, or open a new Terminal tab. That fixed my particular problem.

Unfortunately, the change is temporary. Later, when you open a new Terminal window, you'll be back with your old value and problem.



来源:https://stackoverflow.com/questions/40617651/cannot-change-the-maximum-open-files-per-process-with-sysctl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!