Linux命令之sync - 強制將內存中的文件緩衝內容寫到磁盤

轉:http://www.linuxso.com/command/sync.htmlphp

 

sync命令 linux同步數據命令html

格式: sync node

用途:更新 i-node 表,並將緩衝文件寫到硬盤中。linux

功能:sync命令是在關閉Linux系統時使用的。 用戶須要注意的是,不能用簡單的關閉電源的方法關閉系統,由於Linux象其餘Unix系統同樣,在內存中緩存了許多數據,在關閉系統時須要進行內存數據 與硬盤數據的同步校驗,保證硬盤數據在關閉系統時是最新的,只有這樣才能確保數據不會丟失。通常正常的關閉系統的過程是自動進行這些工做的,在系統運行過 程中也會定時作這些工做,不須要用戶干預。 sync命令是強制把內存中的數據寫回硬盤,以避免數據的丟失。用戶能夠在須要的時候使用此命令。web

sync 命令運行 sync 子例程。若是必須中止系統,則運行 sync 命令以確保文件系統的完整性。sync 命令將全部未寫的系統緩衝區寫到磁盤中,包含已修改的 i-node、已延遲的塊 I/O 和讀寫映射文件。緩存

 

轉:http://codingstandards.iteye.com/blog/995809spa

 

 

用途說明

 

Linux內核爲了達到最佳的磁盤操做效率,會把須要寫入到磁盤的數據如今內存中緩存起來,在合適的時候才真正寫入到磁盤中,這在絕大多數狀況都是 沒有任何問題的,並且提升了系統的效率,可是若是系統當機、掉電,就會有些文件內容不會保存下來。在Linux系統關機或者重啓時,會自動把緩衝區的內容 自動同步到磁盤中。咱們也能夠手工去執行sync命令,強制將內存中的文件緩衝內容寫到磁盤,這個命令是經過調用sync系統調用來實現的。(flush file system buffers。Synchronize data on disk with memory。Force changed blocks to disk, update the super block.`sync' writes any data buffered in memory out to disk.  This can include (but is not limited to) modified superblocks, modified inodes, and delayed reads and writes.  This must be implemented by the kernel; The `sync' program does nothing but exercise the `sync' system call.   The kernel keeps data in memory to avoid doing (relatively slow) disk reads and writes.  This improves performance, but if the computer crashes, data may be lost or the file system corrupted as a result. The `sync' command ensures everything in memory is written to disk.)可是,我認爲通常狀況下咱們是沒有必要去執行這個命令的,由於Linux內核會盡快讓內存中的數據自動同步到磁盤上去,並且,誰又會知道什麼 時候會掉電或當機呢?.net

 

 

 

經常使用方式

 

格式:syncorm

 

強制將內存中的文件緩衝內容寫到磁盤。htm

 

 

 

使用示例

 

示例一

 

[root@web ~]# sync
[root@web ~]#

 

 

 

示例二

 

問題思考

 

1. 在之前使用Unix(SCO Unix, Sun OS)的時候,那些人教咱們使用sync命令,因此記住了它,有些文章也說在關閉或重啓系統以前要屢次執行sync命令,有的說要2此,有的說最好4次。各位看官,大家怎麼看待這個問題,歡迎留言賜教。

 

 

 

相關資料

 

【1】肚子網 linux命令sync用法詳解 http://www.duzi.cn/article/2010-3-12/223585-1.htm 【2】loongene的博客 Linux sync命令的做用 http://blog.sina.com.cn/s/blog_53689eaf0100o8b4.html 【3】IT INF Linux sync命令詳解 http://www.itinf.com/bbs/viewthread.php?tid=66500&extra=page%3D1 【4】CCF技術論壇 【求助】LINUX關機以前,是否必定要sync呢? https://bbs.et8.net/bbs/archive/index.php/t-374736.html

相關文章
相關標籤/搜索