{"id":7149,"date":"2014-05-26T07:47:25","date_gmt":"2014-05-26T07:47:25","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/26\/du-skh-in-returns-vastly-different-size-from-df-on-centos-5-5-collection-of-common-programming-errors\/"},"modified":"2014-05-26T07:47:25","modified_gmt":"2014-05-26T07:47:25","slug":"du-skh-in-returns-vastly-different-size-from-df-on-centos-5-5-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/26\/du-skh-in-returns-vastly-different-size-from-df-on-centos-5-5-collection-of-common-programming-errors\/","title":{"rendered":"du -skh * in \/ returns vastly different size from df on centos 5.5-Collection of common programming errors"},"content":{"rendered":"<p>The most common cause of this effect is open files that have been deleted.<\/p>\n<p>The kernel will only free the disk blocks of a deleted file if it is not in use at the time of its deletion. Otherwise that is deferred until the file is closed, or the system is rebooted.<\/p>\n<p>A common Unix-world trick to ensure that no temporary files are left around is the following:<\/p>\n<ul>\n<li>\n<p>A process creates and opens a temporary file<\/p>\n<\/li>\n<li>\n<p>While still holding the open file descriptor, the process unlinks (i.e. deletes) the file<\/p>\n<\/li>\n<li>\n<p>The process reads and writes to the file normally using the file descriptor<\/p>\n<\/li>\n<li>\n<p>The process closes the file descriptor when it&#8217;s done, and the kernel frees the space<\/p>\n<\/li>\n<li>\n<p>If the process (or the system) terminates unexpectedly, the temporary file is already deleted and no clean-up is necessary.<\/p>\n<\/li>\n<li>\n<p>As a bonus, deleting the file reduces the chances of naming collisions when creating temporary files and it also provides an additional layer of obscurity over the running processes &#8211; for anyone but the root user, that is.<\/p>\n<\/li>\n<\/ul>\n<p>This behaviour ensures that processes don&#8217;t have to deal with files that are suddenly pulled from under their feet, and also that processes don&#8217;t have to consult each other in order to delete a file. It is unexpected behaviour for those coming from Windows systems, though, since there you are not normally allowed to delete a file that is in use.<\/p>\n<p>The <code>lsof<\/code> command, when run as root, will show all open files and it will specifically indicate deleted files that are deleted:<\/p>\n<pre><code># lsof 2&gt;\/dev\/null | grep deleted\nbootlogd   2024       root    1w      REG                9,3         58     917506 \/tmp\/init.0W2ARi (deleted)\nbootlogd   2024       root    2w      REG                9,3         58     917506 \/tmp\/init.0W2ARi (deleted)\n<\/code><\/pre>\n<p>Stopping and restarting the guilty processes, or just rebooting the server should solve this issue.<\/p>\n<p>Deleted files could also be held open by the kernel if, for example, it&#8217;s a mounted filesystem image. In this case unmounting the filesystem or rebooting the server should do the trick.<\/p>\n<p>In your case, judging by the size of the &#8220;missing&#8221; space I&#8217;d look for any references to the file that you used to set up the VPS e.g. the Centos DVD image that you deleted after installing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The most common cause of this effect is open files that have been deleted. The kernel will only free the disk blocks of a deleted file if it is not in use at the time of its deletion. Otherwise that is deferred until the file is closed, or the system is rebooted. A common Unix-world [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7149","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7149"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7149\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}