Failure after writing to linux

What happens if I use write () to write some data to a file on disk. But my application should have worked before flushing. Is it guaranteed that my data will eventually be flushed to disk if there is no system crash?

+4
source share
1 answer

If you use write (and not fwrite or std::ostream::write ), then there is no process buffering. If there is no system failure, then sooner or later (and generally pretty soon) the data will be written to disk.

If you are really concerned about data integrity, you can either in the O_DSYNC and O_SYNC flags to the flags when opening the file. If you do this, it ensures that the data is physically written to disk before returning from write .

+3
source

Source: https://habr.com/ru/post/1413726/


All Articles