{"id":409,"date":"2016-05-19T22:30:04","date_gmt":"2016-05-19T14:30:04","guid":{"rendered":"http:\/\/owemeawe.com\/?p=409"},"modified":"2016-08-28T12:20:31","modified_gmt":"2016-08-28T04:20:31","slug":"lsof%e5%91%bd%e4%bb%a4%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/peloo.net\/?p=409","title":{"rendered":"lsof\u547d\u4ee4\u8be6\u89e3"},"content":{"rendered":"<div><\/div>\n<div><\/div>\n<div>Lsof\u662f\u9075\u4eceUnix\u54f2\u5b66\u7684\u5178\u8303\uff0c\u5b83\u53ea\u5b8c\u6210\u4e00\u4e2a\u529f\u80fd\uff0c\u5e76\u4e14\u505a\u7684\u76f8\u5f53\u5b8c\u7f8e\u2014\u2014\u5b83\u53ef\u4ee5\u5217\u51fa\u67d0\u4e2a\u8fdb\u7a0b\u6253\u5f00\u7684\u6240\u6709\u6587\u4ef6\u4fe1\u606f\u3002\u6253\u5f00\u7684\u6587\u4ef6\u53ef\u80fd\u662f\u666e\u901a\u7684\u6587\u4ef6\u3001\u76ee\u5f55\u3001NFS\u6587\u4ef6\u3001\u5757\u6587\u4ef6\u3001\u5b57\u7b26\u6587\u4ef6\u3001\u5171\u4eab\u5e93\u3001\u5e38\u89c4\u7ba1\u9053\u3001\u547d\u540d\u7ba1\u9053\u3001\u7b26\u53f7\u94fe\u63a5\u3001Socket\u6d41\u3001\u7f51\u7edcSocket\u3001UNIX\u57dfSocket\uff0c\u4ee5\u53ca\u5176\u5b83\u66f4\u591a\u7c7b\u578b\u3002\u56e0\u4e3a\u201c\u4e00\u5207\u7686\u6587\u4ef6\u201d\u4e43\u4e3aUnix\u7cfb\u7edf\u7684\u91cd\u8981\u54f2\u5b66\u601d\u60f3\u4e4b\u4e00\uff0c\u56e0\u6b64\u53ef\u4ee5\u60f3\u8c61lsof\u547d\u4ee4\u7684\u91cd\u8981\u5730\u4f4d\u3002<\/div>\n<div><\/div>\n<div><\/div>\n<div>lsof \uff3boptions\uff3d filename<\/div>\n<div><\/div>\n<div>lsof\u00a0 \/path\/to\/somefile\uff1a\u663e\u793a\u6253\u5f00\u6307\u5b9a\u6587\u4ef6\u7684\u6240\u6709\u8fdb\u7a0b\u4e4b\u5217\u8868<\/div>\n<div>lsof -c string\uff1a\u663e\u793a\u5176COMMAND\u5217\u4e2d\u5305\u542b\u6307\u5b9a\u5b57\u7b26(string)\u7684\u8fdb\u7a0b\u6240\u6709\u6253\u5f00\u7684\u6587\u4ef6\uff1b\u6b64\u9009\u9879\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\uff0c\u4ee5\u6307\u5b9a\u591a\u4e2a\u6a21\u5f0f\uff1b<\/div>\n<div>lsof -p PID\uff1a\u67e5\u770b\u8be5\u8fdb\u7a0b\u6253\u5f00\u4e86\u54ea\u4e9b\u6587\u4ef6\uff1b\u8fdb\u7a0b\u53f7\u524d\u53ef\u4ee5\u4f7f\u7528\u8131\u5b57\u7b26\u201c^\u201d\u53d6\u53cd\uff1b<\/div>\n<div>lsof -u USERNAME\uff1a\u663e\u793a\u6307\u5b9a\u7528\u6237\u7684\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6\uff1b\u7528\u6237\u540d\u524d\u53ef\u4ee5\u4f7f\u7528\u8131\u5b57\u7b26\u201c^\u201d\u53d6\u53cd\uff0c\u5982\u201clsof -u ^root\u201d\u5219\u7528\u4e8e\u663e\u793a\u975eroot\u7528\u6237\u6253\u5f00\u7684\u6240\u6709\u6587\u4ef6\uff1b<\/div>\n<div>lsof -g GID\uff1a\u663e\u793a\u5f52\u5c5egid\u7684\u8fdb\u7a0b\u60c5\u51b5<\/div>\n<div>lsof +d \/DIR\/\uff1a\u663e\u793a\u6307\u5b9a\u76ee\u5f55\u4e0b\u88ab\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6<\/div>\n<div>lsof +D \/DIR\/\uff1a\u57fa\u672c\u529f\u80fd\u540c\u4e0a\uff0c\u4f46lsof\u4f1a\u5bf9\u6307\u5b9a\u76ee\u5f55\u8fdb\u884c\u9012\u5f52\u67e5\u627e\uff0c\u6ce8\u610f\u8fd9\u4e2a\u53c2\u6570\u8981\u6bd4grep\u7248\u672c\u6162\uff1a<\/div>\n<div>lsof -a\uff1a\u6309\u201c\u4e0e\u201d\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u5982lsof -a -c apache -u apache<\/div>\n<div>lsof -N\uff1a\u5217\u51fa\u6240\u6709NFS\uff08\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf\uff09\u6587\u4ef6<\/div>\n<div>lsof -d FD\uff1a\u663e\u793a\u6307\u5b9a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u76f8\u5173\u8fdb\u7a0b\uff1b\u4e5f\u53ef\u4ee5\u4e3a\u63cf\u8ff0\u7b26\u6307\u5b9a\u4e00\u4e2a\u8303\u56f4\uff0c\u59820-2\u8868\u793a0,1,2\u4e09\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\uff1b\u53e6\u5916\uff0c-d\u8fd8\u652f\u6301\u5176\u5b83\u5f88\u591a\u7279\u6b8a\u503c\uff0c\u5982\uff1a<\/div>\n<div>\u00a0\u00a0\u00a0 mem: \u5217\u51fa\u6240\u6709\u5185\u5b58\u6620\u5c04\u6587\u4ef6\uff1b<\/div>\n<div>\u00a0\u00a0\u00a0 mmap\uff1a\u663e\u793a\u6240\u6709\u5185\u5b58\u6620\u5c04\u8bbe\u5907\uff1b<\/div>\n<div>\u00a0\u00a0\u00a0 txt\uff1a\u5217\u51fa\u6240\u6709\u52a0\u8f7d\u5728\u5185\u5b58\u4e2d\u5e76\u6b63\u5728\u6267\u884c\u7684\u8fdb\u7a0b\uff0c\u5305\u542bcode\u548cdata\uff1b<\/div>\n<div>\u00a0\u00a0\u00a0 cwd\uff1a\u6b63\u5728\u8bbf\u95ee\u5f53\u524d\u76ee\u5f55\u7684\u8fdb\u7a0b\u5217\u8868\uff1b<\/div>\n<div><\/div>\n<div>lsof -n\uff1a\u4e0d\u53cd\u89e3IP\u81f3HOSTNAME<\/div>\n<div>lsof -i\uff1a\u7528\u4ee5\u663e\u793a\u7b26\u5408\u6761\u4ef6\u7684\u8fdb\u7a0b\u60c5\u51b5<\/div>\n<div>lsof -i[46] [protocol][@hostname|hostaddr][:service|port]<\/div>\n<div>\u00a0\u00a0\u00a0 46\uff1aIPv4\u6216IPv6<\/div>\n<div>\u00a0\u00a0\u00a0 protocol\uff1aTCP or UDP<\/div>\n<div>\u00a0\u00a0\u00a0 hostname\uff1aInternet host name<\/div>\n<div>\u00a0\u00a0\u00a0 hostaddr\uff1aIPv4\u5730\u5740<\/div>\n<div>\u00a0\u00a0\u00a0 service\uff1a\/etc\/service\u4e2d\u7684\u670d\u52a1\u540d\u79f0(\u53ef\u4ee5\u4e0d\u53ea\u4e00\u4e2a)<\/div>\n<div>\u00a0\u00a0\u00a0 port\uff1a\u7aef\u53e3\u53f7 (\u53ef\u4ee5\u4e0d\u53ea\u4e00\u4e2a)<\/div>\n<div><\/div>\n<div>\u4f8b\u5982\uff1a \u67e5\u770b22\u7aef\u53e3\u73b0\u5728\u8fd0\u884c\u7684\u60c5\u51b5<\/div>\n<div>[root@www ~]# lsof -i :22<\/div>\n<div>COMMAND\u00a0\u00a0 PID USER\u00a0\u00a0 FD\u00a0\u00a0 TYPE DEVICE SIZE\/OFF NODE NAME<\/div>\n<div>sshd\u00a0\u00a0\u00a0\u00a0 1390 root\u00a0\u00a0\u00a0 3u\u00a0 IPv4\u00a0 13050\u00a0\u00a0\u00a0\u00a0\u00a0 0t0\u00a0 TCP *:ssh (LISTEN)<\/div>\n<div>sshd\u00a0\u00a0\u00a0\u00a0 1390 root\u00a0\u00a0\u00a0 4u\u00a0 IPv6\u00a0 13056\u00a0\u00a0\u00a0\u00a0\u00a0 0t0\u00a0 TCP *:ssh (LISTEN)<\/div>\n<div>sshd\u00a0\u00a0\u00a0 36454 root\u00a0\u00a0\u00a0 3r\u00a0 IPv4\u00a0 94352\u00a0\u00a0\u00a0\u00a0\u00a0 0t0\u00a0 TCP www.magedu.com:ssh-&gt;172.16.0.1:50018 (ESTABLISHED)<\/div>\n<div><\/div>\n<div><\/div>\n<div>\u4e0a\u8ff0\u547d\u4ee4\u4e2d\uff0c\u6bcf\u884c\u663e\u793a\u4e00\u4e2a\u6253\u5f00\u7684\u6587\u4ef6\uff0c\u82e5\u4e0d\u6307\u5b9a\u6761\u4ef6\u9ed8\u8ba4\u5c06\u663e\u793a\u6240\u6709\u8fdb\u7a0b\u6253\u5f00\u7684\u6240\u6709\u6587\u4ef6\u3002lsof\u8f93\u51fa\u5404\u5217\u4fe1\u606f\u7684\u610f\u4e49\u5982\u4e0b\uff1a<\/div>\n<div>\u00a0\u00a0\u00a0 COMMAND\uff1a\u8fdb\u7a0b\u7684\u540d\u79f0<\/div>\n<div>\u00a0\u00a0\u00a0 PID\uff1a\u8fdb\u7a0b\u6807\u8bc6\u7b26<\/div>\n<div>\u00a0\u00a0\u00a0 USER\uff1a\u8fdb\u7a0b\u6240\u6709\u8005<\/div>\n<div>\u00a0\u00a0\u00a0 FD\uff1a\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7\u6587\u4ef6\u63cf\u8ff0\u7b26\u8bc6\u522b\u8be5\u6587\u4ef6\u3002\u5982cwd\u3001txt\u7b49<\/div>\n<div>\u00a0\u00a0\u00a0 TYPE\uff1a\u6587\u4ef6\u7c7b\u578b\uff0c\u5982DIR\u3001REG\u7b49<\/div>\n<div>\u00a0\u00a0\u00a0 DEVICE\uff1a\u6307\u5b9a\u78c1\u76d8\u7684\u540d\u79f0<\/div>\n<div>\u00a0\u00a0\u00a0 SIZE\uff1a\u6587\u4ef6\u7684\u5927\u5c0f<\/div>\n<div>\u00a0\u00a0\u00a0 NODE\uff1a\u7d22\u5f15\u8282\u70b9\uff08\u6587\u4ef6\u5728\u78c1\u76d8\u4e0a\u7684\u6807\u8bc6\uff09<\/div>\n<div>\u00a0\u00a0\u00a0 NAME\uff1a\u6253\u5f00\u6587\u4ef6\u7684\u786e\u5207\u540d\u79f0<\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Lsof\u662f\u9075\u4eceUnix\u54f2\u5b66\u7684\u5178\u8303\uff0c\u5b83\u53ea\u5b8c\u6210\u4e00\u4e2a\u529f\u80fd\uff0c\u5e76\u4e14\u505a\u7684\u76f8\u5f53\u5b8c\u7f8e\u2014\u2014\u5b83\u53ef\u4ee5\u5217\u51fa\u67d0\u4e2a\u8fdb\u7a0b\u6253\u5f00\u7684\u6240\u6709\u6587\u4ef6\u4fe1\u606f\u3002\u6253\u5f00\u7684\u6587\u4ef6\u53ef\u80fd\u662f\u666e\u901a\u7684\u6587\u4ef6\u3001\u76ee\u5f55\u3001NFS\u6587\u4ef6\u3001\u5757\u6587\u4ef6\u3001\u5b57\u7b26\u6587\u4ef6\u3001\u5171\u4eab\u5e93\u3001\u5e38\u89c4\u7ba1\u9053\u3001\u547d\u540d\u7ba1\u9053\u3001\u7b26\u53f7\u94fe\u63a5\u3001Socket\u6d41\u3001\u7f51\u7edcSocket\u3001UNIX\u57dfSocket\uff0c\u4ee5\u53ca\u5176\u5b83\u66f4\u591a\u7c7b\u578b\u3002\u56e0\u4e3a\u201c\u4e00\u5207\u7686\u6587\u4ef6\u201d\u4e43\u4e3aUnix\u7cfb\u7edf\u7684\u91cd\u8981\u54f2\u5b66\u601d\u60f3\u4e4b\u4e00\uff0c\u56e0\u6b64\u53ef\u4ee5\u60f3\u8c61lsof\u547d\u4ee4\u7684\u91cd\u8981\u5730\u4f4d\u3002 lsof \uff3boptions\uff3d filename lsof\u00a0 \/path\/to\/somefile\uff1a\u663e\u793a\u6253\u5f00\u6307\u5b9a\u6587\u4ef6\u7684\u6240\u6709\u8fdb\u7a0b\u4e4b\u5217\u8868 lsof -c string\uff1a\u663e\u793a\u5176COMMAND\u5217\u4e2d\u5305\u542b\u6307\u5b9a\u5b57\u7b26(string)\u7684\u8fdb\u7a0b\u6240\u6709\u6253\u5f00\u7684\u6587\u4ef6\uff1b\u6b64\u9009\u9879\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\uff0c\u4ee5\u6307\u5b9a\u591a\u4e2a\u6a21\u5f0f\uff1b lsof -p PID\uff1a\u67e5\u770b\u8be5\u8fdb\u7a0b\u6253\u5f00\u4e86\u54ea\u4e9b\u6587\u4ef6\uff1b\u8fdb\u7a0b\u53f7\u524d\u53ef\u4ee5\u4f7f\u7528\u8131\u5b57\u7b26\u201c^\u201d\u53d6\u53cd\uff1b lsof -u USERNAME\uff1a\u663e\u793a\u6307\u5b9a\u7528\u6237\u7684\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6\uff1b\u7528\u6237\u540d\u524d\u53ef\u4ee5\u4f7f\u7528\u8131\u5b57\u7b26\u201c^\u201d\u53d6\u53cd\uff0c\u5982\u201clsof -u ^root\u201d\u5219\u7528\u4e8e\u663e\u793a\u975eroot\u7528\u6237\u6253\u5f00\u7684\u6240\u6709\u6587\u4ef6\uff1b lsof -g GID\uff1a\u663e\u793a\u5f52\u5c5egid\u7684\u8fdb\u7a0b\u60c5\u51b5 lsof +d \/DIR\/\uff1a\u663e\u793a\u6307\u5b9a\u76ee\u5f55\u4e0b\u88ab\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6 lsof +D \/DIR\/\uff1a\u57fa\u672c\u529f\u80fd\u540c\u4e0a\uff0c\u4f46lsof\u4f1a\u5bf9\u6307\u5b9a\u76ee\u5f55\u8fdb\u884c\u9012\u5f52\u67e5\u627e\uff0c\u6ce8\u610f\u8fd9\u4e2a\u53c2\u6570\u8981\u6bd4grep\u7248\u672c\u6162\uff1a lsof -a\uff1a\u6309\u201c\u4e0e\u201d\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u5982lsof -a -c apache -u apache lsof -N\uff1a\u5217\u51fa\u6240\u6709NFS\uff08\u7f51\u7edc\u6587\u4ef6\u7cfb\u7edf\uff09\u6587\u4ef6 lsof -d FD\uff1a\u663e\u793a\u6307\u5b9a\u6587\u4ef6\u63cf\u8ff0\u7b26\u7684\u76f8\u5173\u8fdb\u7a0b\uff1b\u4e5f\u53ef\u4ee5\u4e3a\u63cf\u8ff0\u7b26\u6307\u5b9a\u4e00\u4e2a\u8303\u56f4\uff0c\u59820-2\u8868\u793a0,1,2\u4e09\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26\uff1b\u53e6\u5916\uff0c-d\u8fd8\u652f\u6301\u5176\u5b83\u5f88\u591a\u7279\u6b8a\u503c\uff0c\u5982\uff1a \u00a0\u00a0\u00a0 mem: \u5217\u51fa\u6240\u6709\u5185\u5b58\u6620\u5c04\u6587\u4ef6\uff1b \u00a0\u00a0\u00a0 mmap\uff1a\u663e\u793a\u6240\u6709\u5185\u5b58\u6620\u5c04\u8bbe\u5907\uff1b \u00a0\u00a0\u00a0 txt\uff1a\u5217\u51fa\u6240\u6709\u52a0\u8f7d\u5728\u5185\u5b58\u4e2d\u5e76\u6b63\u5728\u6267\u884c\u7684\u8fdb\u7a0b\uff0c\u5305\u542bcode\u548cdata\uff1b \u00a0\u00a0\u00a0 cwd\uff1a\u6b63\u5728\u8bbf\u95ee\u5f53\u524d\u76ee\u5f55\u7684\u8fdb\u7a0b\u5217\u8868\uff1b lsof -n\uff1a\u4e0d\u53cd\u89e3IP\u81f3HOSTNAME lsof -i\uff1a\u7528\u4ee5\u663e\u793a\u7b26\u5408\u6761\u4ef6\u7684\u8fdb\u7a0b\u60c5\u51b5 lsof -i[46] [protocol][@hostname|hostaddr][:service|port] \u00a0\u00a0\u00a0&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-409","post","type-post","status-publish","format-standard","hentry","category-linux-shell"],"aioseo_notices":[],"brizy_media":[],"_links":{"self":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=409"}],"version-history":[{"count":1,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/409\/revisions"}],"predecessor-version":[{"id":410,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/409\/revisions\/410"}],"wp:attachment":[{"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}