{"id":65,"date":"2007-11-20T01:02:32","date_gmt":"2007-11-19T17:02:32","guid":{"rendered":"http:\/\/blog.urdada.net\/2007\/11\/20\/65\/"},"modified":"2008-12-22T01:23:43","modified_gmt":"2008-12-21T17:23:43","slug":"disapeared-harddisk-space","status":"publish","type":"post","link":"https:\/\/dada.tw\/blog\/2007\/11\/20\/65\/","title":{"rendered":"\u6d88\u5931\u7684\u786c\u789f\u7a7a\u9593"},"content":{"rendered":"<p>\u8a71\u8aaa\u67d0\u4e00\u5929\uff0c\u4e00\u4f4d\u540c\u4e8b\u767c\u73fe\u67d0\u500b\u5728 UNIX \u4e0a\u7528 C \u5beb\u7684\u7a0b\u5f0f\uff0c\u8dd1\u4e00\u9663\u5b50\u5f8c\u4f3c\u4e4e\u6703\u5403\u6389\u5f88\u591a\u786c\u789f\u7a7a\u9593\uff0c\u5403\u6389\u7684\u786c\u789f\u7a7a\u9593\u7528 du \u53bb\u7b97\u537b\u8ddf df \u7684\u7d50\u679c\u5dee\u7570\u5f88\u5927\uff0c\u800c\u4e14\u628a process \u505c\u6389\u5f8c\uff0c\u7a7a\u9593\u7adf\u7136\u53c8\u81ea\u52d5\u6062\u5fa9\u6b63\u5e38\u4e86<\/p>\n<p>\u6700\u5f8c\uff0c\u7528 fstat \u53bb\u4ed4\u7d30\u5206\u6790\uff0c\u7d42\u65bc\u627e\u5230\u539f\u56e0\uff1a<\/p>\n<blockquote><p><strong>\u5df2\u7d93\u958b\u555f\u7684\u6a94\u6848\uff0c\u5373\u4f7f\u958b\u555f\u4e2d\u88ab\u5f37\u5236\u780d\u6389(unlink)\uff0c\u5c0d\u539f file descriptor \u6301\u7e8c\u5beb\u5165\u7684\u90e8\u4efd\u4ecd\u6703\u7e7c\u7e8c\u4f54\u7528\u786c\u789f\u7a7a\u9593\uff0c\u5beb\u5f97\u8d8a\u591a\uff0c\u4f54\u7528\u7684\u7a7a\u9593\u4e5f\u8d8a\u591a<\/strong><\/p><\/blockquote>\n<p>\u5be6\u52d9\u4e0a\u6700\u5e38\u9047\u5230\u9019\u7a2e\u72c0\u6cc1\u7684\u5c31\u662f log rotation\uff0c\u5c24\u5176\u662f rotation \u5f8c\u7684\u820a LOG \u662f\u58d3\u7e2e\u904e\u7684\u60c5\u6cc1\u3002\u56e0\u70ba\u7d93\u904e gzip \u58d3\u7e2e\u904e\u5f8c\uff0c\u539f\u59cb\u7684 LOG \u6703\u88ab\u522a\u9664\uff0c\u53ea\u7559\u4e0b XXX.gz\u3002\u9019\u500b\u6642\u5019\u5982\u679c\u6c92\u6709\u4eba\u901a\u77e5\u539f\u4f86\u5beb LOG \u7684\u7a0b\u5f0f\u8981\u91cd\u65b0\u958b\u555f\u4e00\u6b21 LOG (\u91cd\u65b0\u5beb\u4e00\u500b\u6a94\u6848)\uff0c\u5c31\u6703\u5c0e\u81f4\u7a0b\u5f0f\u5728\u4e0d\u77e5\u60c5\u72c0\u6cc1\u4e0b\u7e7c\u7e8c\u5beb LOG\uff0c\u7136\u5f8c\u7a7a\u9593\u5c31\u83ab\u540d\u5176\u5999\u88ab\u7528\u6389\u4e86\uff01<\/p>\n<p>\u4f8b\u5982 <a href=http:\/\/www.freebsd.org\/ target=_blank>FreeBSD<\/a> \u4e0b\u5c08\u9580\u4f5c log rotation \u7684 <a href=http:\/\/www.freebsd.org\/cgi\/man.cgi?query=newsyslog&#038;sektion=8 target=_blank>newsyslog<\/a> \u8a2d\u5b9a\u6a94 (<a href=http:\/\/www.freebsd.org\/cgi\/man.cgi?query=newsyslog.conf&#038;sektion=5&#038;apropos=0&#038;manpath=FreeBSD+6.2-RELEASE target=_blank>newsyslog.conf<\/a>) \u5c31\u6709\u500b\u6b04\u4f4d\u53ef\u4ee5\u8a2d\u5b9a\u5728 log rotation \u5f8c\u9001\u4e00\u500b signal \u7d66 process\uff0c\u800c apache (httpd) \u5c31\u63a5\u53d7 SIGUSR1 \u4f86\u7576\u4f5c\u91cd\u65b0\u958b\u555f LOG \u6a94\u6848\u7684\u8a0a\u865f\uff08\u4e8b\u5be6\u4e0a\u5c0d apache \u800c\u8a00\u662f graceful restart\uff09\u3002\u5f88\u591a\u4eba\u4ee5\u70ba\u9019\u53ea\u662f\u70ba\u4e86\u8b93 LOG \u80fd\u7e7c\u7e8c\u5beb\u4e0d\u6703\u6f0f\u6389\uff0c\u4f46\u5176\u5be6\u66f4\u91cd\u8981\u7684\u662f\uff1a\u5982\u679c\u4e0d\u9019\u9ebc\u4f5c\uff0c\u4f60\u7684\u786c\u789f\u53ef\u80fd\u5f88\u5feb\u5c31\u7206\u6389\u5566&#8230;<\/p>\n<p>\u6211\u5011\u53ef\u4ee5\u5beb\u500b\u7c21\u55ae\u7684\u7a0b\u5f0f\u4f86\u6e2c\u8a66\u4e00\u4e0b\u9019\u7a2e\u72c0\u6cc1\uff1a<\/p>\n<pre lang=\"c\" line=\"1\">\r\n#include <stdio.h>\r\n#include <fcntl.h>\r\nint main()\r\n{\r\n        int     fd, i;\r\n        char    cmd[32], buf[1024];\r\n        memset( buf, 0, 1024);\r\n        snprintf(cmd,sizeof(cmd),\"df .\");\r\n\r\n        printf(\"==> open file for write and delete it ...\\n\");\r\n        fd = open( \"test-file.log\", O_CREAT|O_WRONLY|O_TRUNC );\r\n        unlink(\"test-file.log\");\r\n        system(cmd);\r\n\r\n        printf(\"\\n==> write 100MB to file ...\\n\");\r\n        for( i = 0 ; i < 1000*100 ; i++ )\r\n                write( fd, buf, 1024);\r\n        system(cmd);\r\n\r\n        printf(\"\\n==> close file ...\\n\");\r\n        close(fd);\r\n        system(cmd);\r\n}\r\n<\/pre>\n<p>\u9996\u5148\uff0c\u9019\u500b\u5c0f\u7a0b\u5f0f\u6703\u5148\u958b\u555f\u4e00\u500b\u6a94\u6848\uff0c\u7136\u5f8c\u99ac\u4e0a\u780d\u6389\u5b83\uff08\u4f46\u5148\u4e0d\u95dc\u9589\u6a94\u6848\uff09\uff0c\u63a5\u4e0b\u4f86\u57f7\u884c &#8220;df .&#8221; \u4f86\u67e5\u770b\u76ee\u524d\u786c\u789f\u7528\u91cf\u3002\u7b2c\u4e8c\u6b65\u9a5f\u662f\u5beb\u5165100MB\u7684\u5783\u573e\u8cc7\u6599\u5230\u9019\u500b\u5df2\u958b\u555f\u7684\u6a94\u6848(file descriptor)\u4e2d\uff0c\u7136\u5f8c\u518d\u57f7\u884c &#8220;df .&#8221; \u4f86\u53d6\u5f97\u786c\u789f\u7528\u91cf\u3002\u6700\u5f8c\u95dc\u9589\u6a94\u6848\u5f8c\uff0c\u518d\u57f7\u884c\u4e00\u6b21 &#8220;df .&#8221;\u3002\u57f7\u884c\u7d50\u679c\u5982\u4e0b\uff1a<\/p>\n<pre class=mono>\r\n==> open file for write and delete it ...\r\nFilesystem  1K-blocks     Used     Avail Capacity  Mounted on\r\n\/dev\/ad8s1d 144520482 <u>28011428<\/u> 104947416    21%    \/home\r\n\r\n==> write 100MB to file ...\r\nFilesystem  1K-blocks     Used     Avail Capacity  Mounted on\r\n\/dev\/ad8s1d 144520482 <u>28111508<\/u> 104847336    21%    \/home\r\n\r\n==> close file ...\r\nFilesystem  1K-blocks     Used     Avail Capacity  Mounted on\r\n\/dev\/ad8s1d 144520482 <u>28011428<\/u> 104947416    21%    \/home\r\n<\/pre>\n<p>\u6211\u5011\u53ef\u4ee5\u770b\u5230\u7a0b\u5f0f\u5beb\u4e86100MB\u4e4b\u5f8c\uff0c\u7a7a\u9593\u771f\u7684\u88ab\u4f54\u6389\u4e86\uff0c\u5373\u4f7f\u6211\u5011\u5df2\u7d93\u522a\u9664\u9019\u500b\u6a94\u6848\uff0c\u4e14\u5f9e\u76ee\u9304\u7684\u6a94\u6848\u5217\u8868\u4e2d\u7121\u6cd5\u76f4\u63a5\u770b\u5230\u9019\u500b\u6a94\u6848\u4e86\u3002\u800c\u7576\u88ab\u958b\u555f\u7684\u6a94\u6848\u95dc\u6389\u5f8c\uff0c\u9019\u4e9b\u7a7a\u9593\u4e5f\u7acb\u5373\u88ab\u91cb\u653e\u56de\u4f86\u4e86<\/p>\n<p>\u63a5\u4e0b\u4f86\u6211\u5011\u628a\u7a0b\u5f0f\u4e2d\u7684 df \u6539\u6210 fstat\uff0c\u53ef\u4ee5\u66f4\u6e05\u695a\u770b\u5230\u72c0\u6cc1<\/p>\n<pre lang=\"c\" line=\"1\">\r\n        snprintf(cmd,sizeof(cmd),\"fstat -f -p %d .\", getpid());\r\n<\/pre>\n<p>\u9019\u662f\u6700\u5f8c\u7684\u7d50\u679c\uff1a<\/p>\n<pre class=mono>\r\n==> open file for write and delete it ...\r\nUSER     CMD     PID   FD MOUNT     INUM MODE         SZ|DV R\/W\r\ncdsheen  a.out 91475   wd \/home 12694528 drwxr-xr-x    2048  r\r\ncdsheen  a.out 91475 text \/home 12694672 -rwxr-xr-x    7910  r\r\ncdsheen  a.out 91475    3 \/home 12694673 ----r-x--x       0  w\r\n\r\n==> write 100MB to file ...\r\nUSER     CMD     PID   FD MOUNT     INUM MODE         SZ|DV R\/W\r\ncdsheen  a.out 91475   wd \/home 12694528 drwxr-xr-x    2048  r\r\ncdsheen  a.out 91475 text \/home 12694672 -rwxr-xr-x    7910  r\r\ncdsheen  a.out 91475    3 \/home 12694673 ----r-x--x  <u>102400000<\/u>  w\r\n\r\n==> close file ...\r\nUSER     CMD     PID   FD MOUNT     INUM MODE         SZ|DV R\/W\r\ncdsheen  a.out 91475   wd \/home 12694528 drwxr-xr-x    2048  r\r\ncdsheen  a.out 91475 text \/home 12694672 -rwxr-xr-x    7910  r\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8a71\u8aaa\u67d0\u4e00\u5929\uff0c\u4e00\u4f4d\u540c\u4e8b\u767c\u73fe\u67d0\u500b\u5728 UNIX \u4e0a\u7528 C \u5beb\u7684\u7a0b\u5f0f\uff0c\u8dd1\u4e00\u9663\u5b50\u5f8c\u4f3c\u4e4e\u6703\u5403\u6389\u5f88\u591a\u786c\u789f\u7a7a\u9593\uff0c\u5403\u6389\u7684\u786c\u789f\u7a7a\u9593 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9,10],"tags":[19,22,20,21,18],"class_list":["post-65","post","type-post","status-publish","format-standard","hentry","category-os","category-language","tag-disk","tag-fstat","tag-log","tag-rotation","tag-storage"],"views":4841,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pubdi-13","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":84,"url":"https:\/\/dada.tw\/blog\/2008\/04\/18\/84\/","url_meta":{"origin":65,"position":0},"title":"Bypass the 2GB file size limit on 32-bit Linux","author":"dada","date":"2008-04-18","format":false,"excerpt":"Bypass the 2GB file size limit on 32-bit Linux (\u5728 \u2026","rel":"","context":"\u5728\u300c\u4f5c\u696d\u7cfb\u7d71\u300d\u4e2d","block_context":{"text":"\u4f5c\u696d\u7cfb\u7d71","link":"https:\/\/dada.tw\/blog\/category\/comp\/os\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":69,"url":"https:\/\/dada.tw\/blog\/2007\/12\/24\/69\/","url_meta":{"origin":65,"position":1},"title":"Script: \u53d6\u5f97 FreeBSD CVSUP \u7684\u66f4\u65b0\u72c0\u614b","author":"dada","date":"2007-12-24","format":false,"excerpt":"\u9019\u662f\u4eca\u5e741\u6708\u5beb\u7684 script... \u7528\u4f86\u76e3\u63a7\u5404\u5927 FreeBSD CVSUP mirror \u7db2\u7ad9\u7684\u2026","rel":"","context":"\u5728\u300c\u8edf\u9ad4\u300d\u4e2d","block_context":{"text":"\u8edf\u9ad4","link":"https:\/\/dada.tw\/blog\/category\/comp\/software\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":88,"url":"https:\/\/dada.tw\/blog\/2008\/07\/30\/88\/","url_meta":{"origin":65,"position":2},"title":"Subversion pre-commit hook","author":"dada","date":"2008-07-30","format":false,"excerpt":"\u5f88\u591a\u4eba\u5beb\u5b8c\u7a0b\u5f0f\u8981 commit \u7684\u6642\u5019\u6703\u5077\u61f6\u4e0d\u5beb log\uff0c\u5c0e\u81f4\u6709\u6642\u5019\u8981\u8ffd\u554f\u984c\u6642\uff0c \u5f88\u96e3\u5f97\u77e5\u5230\u5e95\u5225\u4eba\u6539\u2026","rel":"","context":"\u5728\u300c\u8edf\u9ad4\u300d\u4e2d","block_context":{"text":"\u8edf\u9ad4","link":"https:\/\/dada.tw\/blog\/category\/comp\/software\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":785,"url":"https:\/\/dada.tw\/blog\/2014\/11\/16\/785\/","url_meta":{"origin":65,"position":3},"title":"\u96f2\u7aef\u6a94\u6848\u540c\u6b65\u610f\u5916\u7684\u6559\u8a13\uff1a\u5373\u6642\u96f2\u7aef\u540c\u6b65\u4e0d\u80fd\u4f5c\u70ba\u5099\u4efd\u4e4b\u7528","author":"dada","date":"2014-11-16","format":false,"excerpt":"\u8a71\u8aaa Dropbox \u4e00\u76f4\u662f\u6211\u62ff\u4f86\u7576\u4f5c\u5099\u4efd\u786c\u789f\u8cc7\u6599\u4f7f\u7528\u7684\u91cd\u8981\u96f2\u7aef\u670d\u52d9 \u6158\u4e8b\u662f\u9019\u9ebc\u767c\u751f\u7684\uff1a \u9996\u5148\u662f\u6211\u7684\u2026","rel":"","context":"\u5728\u300c\u7db2\u8def\u79d1\u6280\u300d\u4e2d","block_context":{"text":"\u7db2\u8def\u79d1\u6280","link":"https:\/\/dada.tw\/blog\/category\/network\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":29,"url":"https:\/\/dada.tw\/blog\/2005\/03\/25\/29\/","url_meta":{"origin":65,"position":4},"title":"Replication of MySQL database","author":"dada","date":"2005-03-25","format":false,"excerpt":"MySQL database \u81ea 3.23.15 \u7248\u4ee5\u5f8c\u5c31\u652f\u63f4 Replication \u529f\u80fd\uff0c\u4f7f\u7528 \u2026","rel":"","context":"\u5728\u300c\u8edf\u9ad4\u300d\u4e2d","block_context":{"text":"\u8edf\u9ad4","link":"https:\/\/dada.tw\/blog\/category\/comp\/software\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":426,"url":"https:\/\/dada.tw\/blog\/2011\/10\/28\/426\/","url_meta":{"origin":65,"position":5},"title":"\u5657\u6d6a\u6a5f\u5668\u4eba\u7bc4\u4f8b\u7a0b\u5f0f &#8211; \u4f7f\u7528 Plurk API 2.0","author":"dada","date":"2011-10-28","format":false,"excerpt":"\u9019\u7bc7\u6587\u7ae0\u8aaa\u660e\u5982\u4f55\u7528 Plurk API 2.0 \u81ea\u5df1\u5beb\u4e00\u500b\u5657\u6d6a\u6a5f\u5668\u4eba (\u672c\u6587\u540c\u6b65\u767c\u8868\u65bc \u5657\u6d6a\u5b98\u65b9\u90e8\u843d\u2026","rel":"","context":"\u5728\u300c\u8edf\u9ad4\u300d\u4e2d","block_context":{"text":"\u8edf\u9ad4","link":"https:\/\/dada.tw\/blog\/category\/comp\/software\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.urdada.net\/wp-content\/uploads\/2011\/10\/bot-11.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":0,"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"wp:attachment":[{"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dada.tw\/blog\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}