But you can't do that... When a program has fork()ed but has not yet called exec() the only system calls it can make are async-signal-safe system calls. opendir() and readdir() are not on that list. Linux is left with no way to close all open file descriptors other than calling close() on all _possible_ file descriptors (a real slow pain in the ass when your max fd limit is in the millions) in between the fork() and exec() to deal with ones that may not have been opened with CLOEXEC.