Most operating systems have limits on how many files a particular process can open at the same time. Since fopen()
is "just" a wrapper on top of open()
, it won't help to use a lower-level interface if this is your problem.
You can verify that this is indeed your problem by checking errno
when fopen()
fails, i.e. if it returns NULL
. You sound as if you've already done this, but you weren't very specific. I would expect EMFILE
if you're running into the per-process limit (see the open()
manual page).
You need to investigate what your particular limits are and see if you can change them, or re-design your program so that you don't open as many files in parallel.