手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆

sync的功能

首页 > Linux >

看好了,這裏寫的是sync不是RSYNC
以前一直不知道是干嘛用的,直到这次。服务器的空间突然间就以每天30G的使用率往上升,以为数据确实在井喷了。在删除掉部分数据后,执行了sync后,突然间又多出150G左右出来

这时候问vampire,他说sync是将内存中的一些信息存储到硬盘上。删除了文件后,如果不执行,很可能空间在运行df的时候,还是在占用状态。

于是查了一下资料 :

http://codingstandards.iteye.com/blog/995809
  1. 用途说明  
  2.   
  3. 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内核会尽快让内存中的数据自动同步到磁盘上去,而且,谁又会知道什么时候会掉电或当机呢?  
  4.   
  5.    
  6. 常用方式  
  7.   
  8. 格式:sync  
  9.   
  10. 强制将内存中的文件缓冲内容写到磁盘。  
  11.   
  12.    
  13. 使用示例  
  14. 示例一  
  15.   
  16. [root@web ~]# sync  
  17. [root@web ~]#  
  18.   
  19.    
  20. 示例二  
  21. 问题思考  
  22.   
  23. 1. 在以前使用Unix(SCO Unix, Sun OS)的时候,那些人教我们使用sync命令,所以记住了它,有些文章也说在关闭或重启系统之前要多次执行sync命令,有的说要2此,有的说最好4次。各位看官,你们怎么看待这个问题,欢迎留言赐教。  
  24.   
  25.    
  26. 相关资料  
  27.   
  28. 【1】肚子网 linux命令sync用法详解  
  29. http://www.duzi.cn/article/2010-3-12/223585-1.htm  
  30. 【2】loongene的博客 Linux sync命令的作用  
  31. http://blog.sina.com.cn/s/blog_53689eaf0100o8b4.html  
  32. 【3】IT INF Linux sync命令详解  
  33. http://www.itinf.com/bbs/viewthread.php?tid=66500&extra=page%3D1  
  34. 【4】CCF技术论坛 【求助】LINUX关机之前,是否一定要sync呢?  
  35. https://bbs.et8.net/bbs/archive/index.php/t-374736.html  

 




本站采用创作共享版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自"易栈网-膘叔", 保留原始链接, 此外还必须标注原文标题和链接.

Tags: sync, rsync

« 上一篇 | 下一篇 »

只显示10条记录相关文章

文件同步工具Unison使用介绍 (浏览: 30129, 评论: 4)
资料:rsync (浏览: 19598, 评论: 3)
月光博客:用dropbox备份网站 (浏览: 17824, 评论: 0)

发表评论

评论内容 (必填):