2012-11-06 44 views
3

在Solaris上執行同步磁盤刷新的最佳方法是什麼?我想刷新所有磁盤,而不是單個文件。Solaris - 同步磁盤刷新/同步同步?

同步()在Solaris(相對於Linux)的異步工作,我正在尋找同步同步()(當它完成它返回)

隨之而來的問題:如何檢查同步做得好?我如何編寫測試顯示它已完成?

謝謝!

回答

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");行添加到您的代碼中。