Normally, the data already written by the application into a kernel buffer with write()
will not be affected by the application exiting or getting killed in any way. Exiting or getting killed implicitly closes all file descriptors, so there should be no difference, the kernel will handle the flushing afterwards. So no fdatasync()
or similar calls are neccessary.
There are two exceptions to this:
if the application uses user-land buffering (not calling the
write()
system call, but instead caching the data in a user-space buffer, withfwrite()
), those buffers might not get flushed unless a proper user-space file close is executed - getting killed by a SIGKILL will definitely cause you to lose the contents of those buffers,if the kernel dies as well (loss of power, kernel crash, etc.), your data might have missed getting written to the disks from the kernel buffers, and will then get lost.