Victor
Victor

Reputation: 1839

Cannot change the maximum open files per process with sysctl

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.

Upvotes: 13

Views: 17460

Answers (2)

Caroline Hill
Caroline Hill

Reputation: 141

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.

Upvotes: 14

Victor
Victor

Reputation: 1839

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.

Upvotes: 25

Related Questions