Various customers are going through an internet site 100% designed in C (CGI). Each web page uses fopen/fgets/fread to see common data (like navigation bars) from files. Would each call to fopen/fgets/fread interefere with one another if various individuals are browsing exactly the same page ? If that's the case, how is this solved in C ? (This can be a Linux server, producing is performed with gcc and to a CGI website designed in C.)

Example:



FILE *DATAFILE = fopen(PATH, "r")

if ( DATAFILE != NULL )





On Linux, it's perfectly safe for multiple ways to concurrently read from the file.

It's perfectly safe to see from multiple processes (in a modern system).

A phone call to fopen() returns a pointer to some FILE structure, which features its own people, like flags, present position, etc.

You need to only care if somebody changes the file (e.g: shrink), while some are reading through it. However I picture this is not your situation.

Concurrent reads from the file (whether from multiple threads -- presuming from individually opened up descriptors -- or from multiple processes) is well-defined and allowed on all modern major os's. It is simply concurrent creates to some file that are ill-defined and which you shouldn't make an effort to do without securing (unless of course you're appending towards the file, just like a log, and also the OS makes such concurrent creates well-defined).