FourOfAKind
FourOfAKind

Reputation: 2418

When does write system call return?

If I'm writing to a file/device in blocking mode does the write() call return on writing all the bytes(assume no signal interruption) to Buffered Cache(Kernel Buffer) or it returns on writing all bytes to the file/device? (This is extension to my earlier question).

Upvotes: 2

Views: 287

Answers (1)

Dietrich Epp
Dietrich Epp

Reputation: 213827

If successful, write returns after writing the data to kernel memory. The write system call makes no guarantees about writing to the disk, you need fsync for that. Actually, fsync does not guarantee that the bits were actually written to the platter itself: just that the IO operation is complete.

(Of course, there are various platform-specific modes and settings you can use to alter this behavior.)

Upvotes: 1

Related Questions