Avoid 'Too many open files' on Unix

Tested on RHEL, Ubuntu and FreeBSD. Please verify that this works with OSX.