B
benjamin.krulewitch
I'm debugging an issue with a C program that causes the computer to
crash, and I'm attempting to log information immediately before the
crash occurs. I us my BKprintLog function (see below) to write
information into a log file. The problem is, i'm not confident that
information i write to the log gets saved onto the hard drive before
the crash occurs.
My understanding of hard drives and OS are that because hard drives are
so slow, that when you write to the harddrive, that information is put
into a buffer, control is returned to the program, and then the
information is saved to permanent storage in the near future. This
application is running on Windows.
Is there any way to guarantee that before my function returns, anything
written to the hard drive is Actually on the hard drive?
The data I'm getting seems to support my concern, as according to the
logs, the crash is occuring at different places each time, and
sometimes, the log file doesn't even get anything written into it
before a crash.
ben
void BKprintLog(char * line) {
FILE * file;
const char * FILENAME = "C:\\log_file.txt";
SYSTEMTIME systime;
GetSystemTime(&systime);
file = fopen(FILENAME,"a+");
fprintf(file, "%2d:%02d:%06.3lf ::
%s\n",systime.wHour,systime.wMinute,systime.wSecond+systime.wMilliseconds/1000.0,line);
fclose(file);
}
crash, and I'm attempting to log information immediately before the
crash occurs. I us my BKprintLog function (see below) to write
information into a log file. The problem is, i'm not confident that
information i write to the log gets saved onto the hard drive before
the crash occurs.
My understanding of hard drives and OS are that because hard drives are
so slow, that when you write to the harddrive, that information is put
into a buffer, control is returned to the program, and then the
information is saved to permanent storage in the near future. This
application is running on Windows.
Is there any way to guarantee that before my function returns, anything
written to the hard drive is Actually on the hard drive?
The data I'm getting seems to support my concern, as according to the
logs, the crash is occuring at different places each time, and
sometimes, the log file doesn't even get anything written into it
before a crash.
ben
void BKprintLog(char * line) {
FILE * file;
const char * FILENAME = "C:\\log_file.txt";
SYSTEMTIME systime;
GetSystemTime(&systime);
file = fopen(FILENAME,"a+");
fprintf(file, "%2d:%02d:%06.3lf ::
%s\n",systime.wHour,systime.wMinute,systime.wSecond+systime.wMilliseconds/1000.0,line);
fclose(file);
}