{"id":3425,"date":"2019-06-22T21:39:55","date_gmt":"2019-06-22T13:39:55","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=3425"},"modified":"2022-05-21T14:17:19","modified_gmt":"2022-05-21T06:17:19","slug":"lsof","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/lsof","title":{"rendered":"lsof\u547d\u4ee4 – \u67e5\u770b\u6587\u4ef6\u7684\u8fdb\u7a0b\u4fe1\u606f"},"content":{"rendered":"\n

lsof\u547d\u4ee4\u6765\u81ea\u4e8e\u82f1\u6587\u8bcd\u7ec4\u201clist opened files\u201d\u7684\u7f29\u5199\uff0c\u5176\u529f\u80fd\u662f\u7528\u4e8e\u67e5\u770b\u6587\u4ef6\u7684\u8fdb\u7a0b\u4fe1\u606f\u3002\u65e2\u7136Linux\u7cfb\u7edf\u4e2d\u7684\u4e00\u5207\u90fd\u662f\u6587\u4ef6\uff0c\u90a3\u4e48\u4f7f\u7528lsof\u547d\u4ee4\u67e5\u770b\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u53c8\u6216\u662f\u67e5\u770b\u6587\u4ef6\u7684\u8fdb\u7a0b\u4fe1\u606f\uff0c\u90fd\u80fd\u591f\u5f88\u597d\u7684\u5e2e\u52a9\u7528\u6237\u4e86\u89e3\u76f8\u5173\u670d\u52a1\u7684\u8fd0\u884c\u72b6\u6001\uff0c\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u7cfb\u7edf\u76d1\u89c6\u5de5\u5177\u3002<\/p>\n\n\n\n

\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong>lsof [\u53c2\u6570] [\u6587\u4ef6]<\/p>\n\n\n\n

\u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n

-a<\/td>\u5217\u51fa\u6253\u5f00\u6587\u4ef6\u5b58\u5728\u7684\u8fdb\u7a0b<\/td><\/tr>
-c <\u8fdb\u7a0b\u540d><\/td>\u5217\u51fa\u6307\u5b9a\u8fdb\u7a0b\u6240\u6253\u5f00\u7684\u6587\u4ef6<\/td><\/tr>
-g<\/td>\u5217\u51faGID\u53f7\u8fdb\u7a0b\u8be6\u60c5<\/td><\/tr>
-d <\u6587\u4ef6\u53f7><\/td>\u5217\u51fa\u5360\u7528\u8be5\u6587\u4ef6\u53f7\u7684\u8fdb\u7a0b<\/td><\/tr>
+d <\u76ee\u5f55><\/td>\u5217\u51fa\u76ee\u5f55\u4e0b\u88ab\u6253\u5f00\u7684\u6587\u4ef6<\/td><\/tr>
+D <\u76ee\u5f55><\/td>\u9012\u5f52\u5217\u51fa\u76ee\u5f55\u4e0b\u88ab\u6253\u5f00\u7684\u6587\u4ef6<\/td><\/tr>
-n <\u76ee\u5f55><\/td>\u5217\u51fa\u4f7f\u7528NFS\u7684\u6587\u4ef6<\/td><\/tr>
-i <\u6761\u4ef6><\/td>\u5217\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u8fdb\u7a0b<\/td><\/tr>
-p <\u8fdb\u7a0b\u53f7><\/td>\u5217\u51fa\u6307\u5b9a\u8fdb\u7a0b\u53f7\u6240\u6253\u5f00\u7684\u6587\u4ef6<\/td><\/tr>
-u<\/td>\u5217\u51faUID\u53f7\u8fdb\u7a0b\u8be6\u60c5<\/td><\/tr>
-h <\/td>\u663e\u793a\u5e2e\u52a9\u4fe1\u606f<\/td><\/tr>
-v<\/td>\u663e\u793a\u7248\u672c\u4fe1\u606f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

\u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n

\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u4e2d\u5168\u90e8\u6587\u4ef6\u4e0e\u8fdb\u7a0b\u5bf9\u5e94\u4fe1\u606f\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# lsof<\/strong> \nCOMMAND    PID  TID TASKCMD   USER   FD      TYPE   DEVICE SIZE\/OFF       NODE NAME\nsystemd      1    root  cwd       DIR              253,0      224        128 \/\nsystemd      1    root  rtd       DIR              253,0      224        128 \/\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n

\u663e\u793a\u6307\u5b9a\u76ee\u5f55\u4e2d\u88ab\u8c03\u7528\u7684\u6587\u4ef6\u4fe1\u606f\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# lsof +d \/root<\/strong>\r\nCOMMAND    PID USER   FD   TYPE DEVICE SIZE\/OFF     NODE NAME\r\ndbus-daem 2158 root  cwd    DIR  253,0     4096 33575041 \/root\r\ngdm-wayla 2161 root  cwd    DIR  253,0     4096 33575041 \/root\r\ngnome-ses 2164 root  cwd    DIR  253,0     4096 33575041 \/root\r\ngnome-she 2223 root  cwd    DIR  253,0     4096 33575041 \/root\r\ngvfsd     2240 root  cwd    DIR  253,0     4096 33575041 \/root\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n

\u9012\u5f52\u663e\u793a\u6307\u5b9a\u76ee\u5f55\u4e2d\u5168\u90e8\u88ab\u8c03\u7528\u7684\u6587\u4ef6\u4fe1\u606f\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# lsof +D \/root<\/strong>\r\nCOMMAND    PID USER   FD   TYPE DEVICE SIZE\/OFF     NODE NAME\r\npulseaudi 2147 root  mem    REG  253,0      696   781661 \/root\/.config\/pulse\/d035ea0c9f884c418d9855119085f3f0-card-database.tdb\r\npulseaudi 2147 root  mem    REG  253,0    12288   781660 \/root\/.config\/pulse\/d035ea0c9f884c418d9855119085f3f0-stream-volumes.tdb\r\npulseaudi 2147 root  mem    REG  253,0     8192   781659 \/root\/.config\/pulse\/d035ea0c9f884c418d9855119085f3f0-device-volumes.tdb\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r<\/pre>\n","protected":false},"excerpt":{"rendered":"

lsof\u547d\u4ee4\u6765\u81ea\u4e8e\u82f1\u6587\u8bcd\u7ec4\u201clist opened files\u201d\u7684\u7f29\u5199\uff0c\u5176\u529f\u80fd\u662f\u7528\u4e8e\u67e5\u770b\u6587\u4ef6\u7684\u8fdb\u7a0b\u4fe1\u606f\u3002\u65e2\u7136L […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/3425"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=3425"}],"version-history":[{"count":41,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/3425\/revisions"}],"predecessor-version":[{"id":9906,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/3425\/revisions\/9906"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=3425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=3425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=3425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}