Reputation: 721
fwrite()
is a library call that firstly buffers the data into a user space buffer, and then calls the write()
system call later to actually carry out the write operations.
If a program invokes
fwrite()
to write some data to a file but then exists abnormally, will the buffer offwrite()
beclearedflushed, or the buffered data will be left over in memory?
The OS I am considering is Linux.
Upvotes: 7
Views: 1077
Reputation: 1365
If your program exited abnormally, any buffered data will not be flushed. The OS just says "oh dear me, you left a file descriptor open, I better close that for you" when the process terminates; it has no idea there's some random data lying somewhere in memory that the program intended to write to disk but did not.
Upvotes: 9