Paul Paul - 1 year ago 76
C++ Question

Is there a reason fopen() wouldn't work after several hundred opens?

Hey, for this piece of code, the person who wrote the system communicates data between processes using textfiles. I have a loops that looks (for all intents and purposes) like this:

while (true)
//get the most up-to-date info from the other processes
pFile = fopen(paramsFileName, "r");

// Do a bunch of stuff with pFile


This will work for several hundred times, but for whatever reason it will return NULL after a while, even though it has opened that same file path several hundred times already! I have double checked that the file exists and has data in it when the fopen returns NULL, and have tried to put a delay/retry in there to no effect.

What can you think of that would cause this?

Answer Source

You're hitting the open file / file descriptor limit for your OS. It should run forever if you do fclose(pFile) in your loop.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download