{"id":18376,"date":"2024-11-18T08:53:41","date_gmt":"2024-11-18T00:53:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18376\/"},"modified":"2024-11-18T08:53:41","modified_gmt":"2024-11-18T00:53:41","slug":"linux%e6%80%8e%e4%b9%88%e6%9f%a5%e7%9c%8b%e8%bf%9b%e7%a8%8b%e5%8d%a0%e7%94%a8%e5%86%85%e5%ad%98","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18376\/","title":{"rendered":"linux\u600e\u4e48\u67e5\u770b\u8fdb\u7a0b\u5360\u7528\u5185\u5b58"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u67e5\u770b linux \u8fdb\u7a0b\u7684\u5185\u5b58\u5360\u7528\uff1f\u547d\u4ee4\u884c\u65b9\u6cd5\uff1aps\u3001top\u3001vmstat\u7cfb\u7edf\u5206\u6790\u5de5\u5177\uff1ahtop\u3001process explorer\u4f7f\u7528 api\uff1a\u7cfb\u7edf\u8c03\u7528\uff08c\/python\uff09\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/17\/2024081718434452906.jpg\" class=\"aligncenter\" title=\"linux\u600e\u4e48\u67e5\u770b\u8fdb\u7a0b\u5360\u7528\u5185\u5b58\u63d2\u56fe\" alt=\"linux\u600e\u4e48\u67e5\u770b\u8fdb\u7a0b\u5360\u7528\u5185\u5b58\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u67e5\u770b Linux \u8fdb\u7a0b\u7684<\/strong><\/p>\n<p>\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u67e5\u770b\u8fdb\u7a0b\u5185\u5b58\u5360\u7528\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u51e0\u79cd\u65b9\u6cd5\u6765\u83b7\u53d6\u6709\u5173\u8fdb\u7a0b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u4fe1\u606f\u3002<\/p>\n<p><strong>\u547d\u4ee4\u884c\u65b9\u6cd5<\/strong><\/p>\n<ul>\n<li><strong>ps\u547d\u4ee4<\/strong><\/li>\n<\/ul>\n<pre>ps -eo pid,comm,%mem,vsz,rss | sort -nrk 3<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u547d\u4ee4\u5c06\u663e\u793a\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u6309\u5185\u5b58\u4f7f\u7528\u767e\u5206\u6bd4\u6392\u5e8f\u3002<\/p>\n<ul>\n<li><strong>top\u547d\u4ee4<\/strong><\/li>\n<\/ul>\n<pre>top -o %MEM<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u547d\u4ee4\u5c06\u663e\u793a\u8fdb\u7a0b\u7684\u52a8\u6001\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u5305\u62ec\u7269\u7406\u5185\u5b58\uff08RSS\uff09\u548c\u865a\u62df\u5185\u5b58\uff08VSZ\uff09\u3002<\/p>\n<ul>\n<li><strong>vmstat\u547d\u4ee4<\/strong><\/li>\n<\/ul>\n<pre>vmstat -s<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u547d\u4ee4\u63d0\u4f9b\u7cfb\u7edf\u7684\u5185\u5b58\u7edf\u8ba1\u6570\u636e\uff0c\u5305\u62ec\u8fdb\u7a0b\u4f7f\u7528\u7684 RSS \u548c VSZ \u5185\u5b58\u3002<\/p>\n<p><strong>\u7cfb\u7edf\u5206\u6790\u5de5\u5177<\/strong><\/p>\n<ul>\n<li><strong>htop<\/strong><\/li>\n<\/ul>\n<p>htop \u662f\u4e00\u6b3e\u57fa\u4e8e\u6587\u672c\u7684\u4ea4\u4e92\u5f0f\u7cfb\u7edf\u76d1\u89c6\u5668\uff0c\u5141\u8bb8\u60a8\u67e5\u770b\u8fdb\u7a0b\u7684\u8be6\u7ec6\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u5305\u62ec\u5171\u4eab\u5185\u5b58\u3001\u79c1\u6709\u5185\u5b58\u548c\u5806\u6808\u5927\u5c0f\u3002<\/p>\n<ul>\n<li><strong>Process Explorer<\/strong><\/li>\n<\/ul>\n<p>Process Explorer \u662f Windows \u548c Linux \u7cfb\u7edf\u4e2d\u4e00\u6b3e\u6d41\u884c\u7684\u56fe\u5f62\u5316\u8fdb\u7a0b\u7ba1\u7406\u5668\uff0c\u63d0\u4f9b\u6709\u5173\u8fdb\u7a0b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u5168\u9762\u4fe1\u606f\u3002<\/p>\n<p><strong>\u901a\u8fc7 API<\/strong><\/p>\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 C \u6216 Python \u7b49\u7f16\u7a0b\u8bed\u8a00\u4e2d\u7684\u7cfb\u7edf\u8c03\u7528\u6765\u83b7\u53d6\u8fdb\u7a0b\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u5728 Python \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>import psutil\nfor proc in psutil.process_iter():\n    mem = proc.memory_info()\n    print(proc.name(), mem.rss)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u6253\u5370\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u540d\u79f0\u53ca\u5176\u9a7b\u7559\u96c6\u5927\u5c0f\uff08RSS\uff09\u3002<\/p>\n<p><strong>\u9009\u62e9\u65b9\u6cd5<\/strong><\/p>\n<p>\u9009\u62e9\u67e5\u770b\u8fdb\u7a0b\u5185\u5b58\u5360\u7528\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u60a8\u9700\u8981\u7684\u8be6\u7ec6\u4fe1\u606f\u7ea7\u522b\u548c\u6240\u4f7f\u7528\u7684\u7cfb\u7edf\u5de5\u5177\u3002\u547d\u4ee4\u884c\u65b9\u6cd5\u6613\u4e8e\u4f7f\u7528\uff0c\u800c\u7cfb\u7edf\u5206\u6790\u5de5\u5177\u63d0\u4f9b\u66f4\u76f4\u89c2\u7684\u754c\u9762\u548c\u66f4\u8be6\u7ec6\u7684\u4fe1\u606f\u3002\u4f7f\u7528 API \u5141\u8bb8\u60a8\u81ea\u5b9a\u4e49\u6570\u636e\u6536\u96c6\u8fc7\u7a0b\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u67e5\u770b\u8fdb\u7a0b\u5360\u7528\u5185\u5b58\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u67e5\u770b linux \u8fdb\u7a0b\u7684\u5185\u5b58\u5360\u7528\uff1f\u547d\u4ee4\u884c\u65b9\u6cd5\uff1aps\u3001top\u3001vmstat\u7cfb\u7edf\u5206\u6790\u5de5\u5177\uff1ahtop\u3001process explorer\u4f7f\u7528 api\uff1a\u7cfb\u7edf\u8c03\u7528\uff08c\/python\uff09 \u5982\u4f55\u67e5\u770b Linux \u8fdb\u7a0b\u7684 \u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u67e5\u770b\u8fdb\u7a0b\u5185\u5b58\u5360\u7528\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u4efb\u52a1\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u51e0\u79cd\u65b9\u6cd5\u6765\u83b7\u53d6\u6709\u5173\u8fdb\u7a0b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u4fe1\u606f\u3002 \u547d\u4ee4\u884c\u65b9\u6cd5 ps\u547d\u4ee4 ps -eo pid,comm,%mem,vsz,rss | sort -nrk 3 \u767b\u5f55\u540e\u590d\u5236 \u8be5\u547d\u4ee4\u5c06\u663e\u793a\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u6309\u5185\u5b58\u4f7f\u7528\u767e\u5206\u6bd4\u6392\u5e8f\u3002 top\u547d\u4ee4 top -o %MEM \u767b\u5f55\u540e\u590d\u5236 \u8be5\u547d\u4ee4\u5c06\u663e\u793a\u8fdb\u7a0b\u7684\u52a8\u6001\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u5305\u62ec\u7269\u7406\u5185\u5b58\uff08RSS\uff09\u548c\u865a\u62df\u5185\u5b58\uff08VSZ\uff09\u3002 vmstat\u547d\u4ee4 vmstat -s \u767b\u5f55\u540e\u590d\u5236 \u8be5\u547d\u4ee4\u63d0\u4f9b\u7cfb\u7edf\u7684\u5185\u5b58\u7edf\u8ba1\u6570\u636e\uff0c\u5305\u62ec\u8fdb\u7a0b\u4f7f\u7528\u7684 RSS \u548c VSZ \u5185\u5b58\u3002 \u7cfb\u7edf\u5206\u6790\u5de5\u5177 htop htop \u662f\u4e00\u6b3e\u57fa\u4e8e\u6587\u672c\u7684\u4ea4\u4e92\u5f0f\u7cfb\u7edf\u76d1\u89c6\u5668\uff0c\u5141\u8bb8\u60a8\u67e5\u770b\u8fdb\u7a0b\u7684\u8be6\u7ec6\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u5305\u62ec\u5171\u4eab\u5185\u5b58\u3001\u79c1\u6709\u5185\u5b58\u548c\u5806\u6808\u5927\u5c0f\u3002 Process Explorer Process Explorer \u662f Windows \u548c Linux \u7cfb\u7edf\u4e2d\u4e00\u6b3e\u6d41\u884c\u7684\u56fe\u5f62\u5316\u8fdb\u7a0b\u7ba1\u7406\u5668\uff0c\u63d0\u4f9b\u6709\u5173\u8fdb\u7a0b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u5168\u9762\u4fe1\u606f\u3002 \u901a\u8fc7 API \u4e5f\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 C \u6216 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-18376","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18376"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18376\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}