Cannot change the maximum open files per process with sysctl

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.


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.