use File::Sync qw(fsync sync); sync(); fsync(\*FILEHANDLE) or die "fsync: $!"; # and if fdatasync() is available on your system: fdatasync($fh) or die "fdatasync: $!"; use File::Sync qw(fsync); use FileHandle; $fh = new FileHandle("> /tmp/foo") or die "new FileHandle: $!"; ... $fh->fsync() or die "fsync: $!";
The fsync_fd() function is used internally by fsync(); it takes a file descriptor as its only argument.
The sync() function is identical to the C function sync().
This module does not export any methods by default, but fsync()
is made available as a method of the FileHandle class. Note carefully
that as of 0.11, we no longer clobber anything in IO::Handle. You
can replace any calls to IO::Handle::fsync() with IO::Handle::sync():