Will the data in the fwrite () buffer be flushed if the program exists abnormally?

fwrite() is a library call that first buffers data into the user space buffer, and then calls the write() system call later to actually perform write operations.

If the program calls fwrite() to write some data to a file, but then abnormally exists, the fwrite() be cleared buffer will be flushed , or the buffered data will be left in memory

I am considering a Linux OS.

+6
source share
1 answer

If your program crashes, any buffered data will not be cleared. The OS simply says, β€œOh dear, you left the file descriptor open, I better close it for you,” when the process ends; he does not suspect that some random data lies somewhere in memory, that the program is designed to be written to disk, but did not.

+8
source

All Articles