# Cannot increase file descriptor limits



## pkc (Aug 4, 2018)

I am trying to increase file descriptor limits using `limits`:


```
# sysctl kern.maxfiles kern.maxfilesperproc
kern.maxfiles: 65536
kern.maxfilesperproc: 65536

# limits -H -n
Resource limits (current):
  openfiles               57870
# limits -H -n 65536
Resource limits (current):
  openfiles-max           65536
# limits -H -n
Resource limits (current):
  openfiles               57870
```

Same thing for -S. What am I doing wrong?


----------



## rigoletto@ (Aug 5, 2018)

I.e. `sysctl kern.maxfiles=NUMBER`

To make it permanent add to /etc/sysctl.conf.


----------



## pkc (Aug 5, 2018)

Thanks, sorry I do not understand your reply. `limits` shows that the limit remains at 57850. Currently the only way I have to work around this is that once I start the application that is complaining, I change the limit for that PID with `-P`.


----------



## rigoletto@ (Aug 5, 2018)

Run `sysctl kern.maxfiles=NUMBER`, where NUMBER is the new limit you want/need to set in bytes.


----------



## Bobi B. (Aug 5, 2018)

As lebarondemerde told you, try to increase system-wide file descriptors limit with `sysctl kern.maxfiles=200000` first.

PS: Out of curiosity, what program needs that many file descriptors?


----------



## rigoletto@ (Aug 5, 2018)

Probably something using kqueue(2) to watch files.


----------



## pkc (Aug 5, 2018)

As I wrote in my original message, `kern.maxfiles` has already been set to 65536. I tried setting it to a higher value, say 1048576, but I have the same issue.

The software is elasticsearch, which even for my small installation apparently has this requirement that cannot be changed unfortunately..


----------



## Bobi B. (Aug 5, 2018)

There is also `sysctl kern.maxfilesperproc=200000`. And then it depends on which shell you use. For sh(1) you should use `ulimit -n 200000`, whereas for csh(1) correct command is `limit descriptors 200000`.


----------

