Solaris - 同步磁盘刷新/同步同步?

时间:2012-11-06 09:32:05

标签: database solaris sync flush

在Solaris上执行同步磁盘刷新的最佳方法是什么?我想刷新所有磁盘,而不是单个文件。

Solaris上的Sync()(与Linux相对)ASYNCHRONOUSLY,我正在寻找SYNCHRONOUS sync()(它完成时返回)

后续问题:如何正确检查同步?如何编写显示已完成的测试?

谢谢!

1 个答案:

答案 0 :(得分:3)

你可以运行:

/usr/sbin/lockfs -af

引用lockfs manual page

  

-f

     Force a synchronous flush of all data that is  dirty  at
     the  time  fsflush  is  run to its backing store for the
     named file system (or for all file systems.)

     It is a more reliable method than using sync(1M) because
     it  does  not  return  until  all possible data has been
     pushed.

如果你想纯粹用C语言,你可以使用

  #include <sys/filio.h>
  ...    
  ioctl(fd, _FIOFFS, NULL);

fd是文件系统挂载点的文件描述符(来自/ etc / mtab)。

请注意_FIOFFS是一个私有接口,因此可能随时消失,恕不另行通知。完全支持且更健壮的方法是简单地将行system("/usr/sbin/lockfs -af");添加到您的代码中。

相关问题