Take the 2-minute tour ×

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer


