zoukankan      html  css  js  c++  java
  • Linux命令之sync

    转:http://www.linuxso.com/command/sync.html

    sync命令 linux同步数据命令

    格式: sync 

    用途:更新 i-node 表,并将缓冲文件写到硬盘中。

    功能:sync命令是在关闭Linux系统时使用的。 用户需要注意的是,不能用简单的关闭电源的方法关闭系统,因为Linux象其他Unix系统一样,在内存中缓存了许多数据,在关闭系统时需要进行内存数据 与硬盘数据的同步校验,保证硬盘数据在关闭系统时是最新的,只有这样才能确保数据不会丢失。一般正常的关闭系统的过程是自动进行这些工作的,在系统运行过 程中也会定时做这些工作,不需要用户干预。 sync命令是强制把内存中的数据写回硬盘,以免数据的丢失。用户可以在需要的时候使用此命令。

    sync 命令运行 sync 子例程。如果必须停止系统,则运行 sync 命令以确保文件系统的完整性。sync 命令将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node、已延迟的块 I/O 和读写映射文件。

     

    转:http://codingstandards.iteye.com/blog/995809

     

     

    用途说明

     

    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内核会尽快让内存中的数据自动同步到磁盘上去,而且,谁又会知道什么 时候会掉电或当机呢?

     

     

    常用方式

     

    格式:sync

     

    强制将内存中的文件缓冲内容写到磁盘。

     

     

    使用示例

     

    示例一

     

    [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

     

  • 相关阅读:
    Python异常详解:基类、具体异常、异常层次结构
    Python视频教程,百度云资源,免费分享
    Python学习路线图(内附14张思维导图)
    Python视频教程免费下载,最新Python免费教程视频分享!
    怎样通过互联网ssh访问家里电脑
    linux下,把屏幕竖起来
    python中函数的不定长参数
    python中全局变量和局部变量
    vbox+Vagrant 入门指南
    python中函数返回多个值
  • 原文地址:https://www.cnblogs.com/pengdonglin137/p/3325662.html
Copyright © 2011-2022 走看看