From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
05-16-2014 09:25 AM
I have an application of mine which is intended to run unattended 24/7 collecting data and handling tests. During the application I periodically save working status informations to disk, with the aim of reloading them at program launch and restart working operation where they have left off the last time.
Informations are a fixed volume of data (<20kb) save every minute on the same file; the file is opened and closed in this operation with this function:
int SaveSts (void) { FILE *stH = NULL; stH = fopen (fsts, "rb+"); if (errno) goto Error; // 's' is an array of structures of 'sz' elements fwrite ((char *)s, sizeof(status), sz, stH); if (errno) goto Error; Error: if (stH) fclose (stH); return errno; }
Now I am facing a strange situation in which the user restarts the program finding that saved situation refers to some moment in the past (from a few minutes to several hours) as if the save function weren't working properly event though no error is found in it. It happens after the system has automatically restarted due to OS updates overnight (the system does not handle a close message from the OS -my bad- so it could close improperly in this situation).
Beyond double checking my program, I am wandering whether it can depend on some hardware or OS characteristics like the disk cache that delays physical write to disk or whatsoever feature I can't imagine at the moment. Also, I don't know if continuously writing the same amount of information on the same file on disk can introduce some unexpected odd behaviour in the system.
Every time I check status file date during program life it is correct, but I could be forcing a disk update just for the fact that I am observing the very file in the Resource Manager
Anybody has some knowledge to share on this? I am a bit lost on how to determine where the problem is and how to solve it...
05-16-2014 09:33 AM
you certainly checked disk write caching.... is it turned off?
Device Manager / Disk Drive / Properties > Policies
05-16-2014 10:16 AM - edited 05-16-2014 10:17 AM
No, I haven't checked and I can't do it now: the PC is on customer's site and I don't have remote access at present. I will contact him and have him check this.
Can this alter normal PC operation and how much? You know, the program is supposed to save test data too while working
Additionally, could disk caching explain that several hour misalignment?
05-16-2014 10:55 AM
You are right, hours sounds like an excellent counter argument, and with 20 kB / minute any buffer should be filled rather quickly (but this was my only idea...)
05-16-2014 11:56 AM
05-16-2014 12:19 PM - edited 05-16-2014 12:20 PM
Fflush is one of the possible additions, perhaps the most immediate to implement, even though I would say that closing the file has the same effect.
I have now working a reduced version of the application with some equipment in my laboratory: next monday I'll see if I can replicate the issue and then apply some correction; fflush and trapping the system closing message are the first I planned.
Other suggestions are welcome