How can this problem be solved? Decide to use the file lock. There are BSD and POSIX File locks, as follows: # if (pai_flock_bsd = 1) ret = flock (fd, LOCK_SH); if (ret! = 0) // can not get R_lock when writting {ret =-100; goto End;} # elif (pai_flock_posix = 1) ret = _ SimpleSetPosixLock (fd, F_RDLCK ); if (ret <0) // can not get R_lock when writting {ret =-100; goto End;} # After endif adds a file lock, this still happens. It was suspected that there was a problem with the file lock itself. The final result is that the file size obtained by stat is incorrect. Replace/stat (pconfig-> fileName, & sb) with ret = fstat (fd, & sb. According to the file name to stat file size, it is possible that the file is being written by another process, then the file is read into the memory according to the incorrect size, write back the file at commit, then an error occurs. The correct operation procedure is: open the file --> apply for a read lock --> fstat size upon success, and read the file into the memory according to the size. In this way, the file will not be damaged. Of course, the API provided by the INI file operation itself also has a defect. When ret fails to return, no exit parameters are set. When the return value fails, the export parameter is also set to an invalid value. # Define NULL_STR '\ 0' # define NULL_VAL 0xFFFFIni configuration file is written in ansi c and easy to transplant. Supports multi-process access with high efficiency. If you have any need, you can leave a message, send a text message or email to me.