df -h与du -h结果不一致的问题分析

    Read


定时任务中有这样一个脚本:

修复后:


可能原因:SourceByrd's Weblog-https://note.t4x.org/error/df-diff-du/

(1)
When you open a file, you get a pointer. Subsequent writes to this file
references this file pointer. The write call does not check to see if the file
is there or not. It just writes to the specified number of characters starting
at a predetermined location. Regardless of whether the file exist or not, disk
blocks are used by the write operation. SourceByrd's Weblog-https://note.t4x.org/error/df-diff-du/

The df command reports the number of disk blocks used while du goes through the
file structure and and reports the number of blocks used by each directory. As
far as du is concerned, the file used by the process does not exist, so it does
not report blocks used by this phantom file. But df keeps track of disk blocks
used, and it reports the blocks used by this phantom file.
以及leolein朋友的回复:
谢谢,就是这个原因。
我因为磁盘快满了就删除了一些过期的文件,可能应用程序还在使用这些文件句柄,所以导致了我说的问题。
我把所有的应用程序都停止后,du和df的结果就大致相同了SourceByrd's Weblog-https://note.t4x.org/error/df-diff-du/

(2):
This section gives the technical explanation of why du and df sometimes report
different totals of disk space usage.SourceByrd's Weblog-https://note.t4x.org/error/df-diff-du/

When a program that is running in the background writes to a file while the
process is running, the file to which this process is writing is deleted.
Running df and du shows a discrepancy in the amount of disk space usage. The
df command shows a higher value. SourceByrd's Weblog-https://note.t4x.org/error/df-diff-du/

参考1:http://www.chinaunix.net/old_jh/6/465673.html
参考2:http://blog.itpub.net/26230597/viewspace-1242675
其他参考:http://www.cnblogs.com/heyonggang/p/3644736.htmlSourceByrd's Weblog-https://note.t4x.org/error/df-diff-du/ SourceByrd's Weblog-https://note.t4x.org/error/df-diff-du/

申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!
Byrd
  • by Published on January 9, 2017
  • 原文链接:https://note.t4x.org/error/df-diff-du/
匿名

Comment

Anonymous

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: