Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Whilst writing some unit tests I hit the upper limit for too many open files (Debian VM) - "failed to open stream: Too many open files"

Other than a restart, is there any way to clear this block? (i.e. will these open, but unaccessed, files be cleaned up over time?)

Fyi - I'd like to know because I want to setup a continuous integration server for unit testing, and if a reboot is the only way to clear this problem then I need to find a different way of approaching certain unit tests.

share|improve this question
up vote 3 down vote accepted

Not unless you close them or the process that owns them dies.

It's possible that the user that you are using to run the tests is constrained by ulimits as to how many files they can open.

share|improve this answer

Did you try to increase the maximum open files for the user under which you run the tests ?

To see how many open files the user has (soft and hard):

# ulimit -Hn
# ulimit -Sn

Also it normal that sometimes you need to increase the global max open files for the system. So try with that and find out if it helps.

# sysctl -w fs.file-max=100000

If you wanna permanently change the max open files you need to edit /etc/sysctl.conf file and add/change the following line

fs.file-max = 100000
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.