{"id":18387,"date":"2024-11-18T09:07:34","date_gmt":"2024-11-18T01:07:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18387\/"},"modified":"2024-11-18T09:07:34","modified_gmt":"2024-11-18T01:07:34","slug":"linux%e6%a0%b9%e6%8d%ae%e8%bf%9b%e7%a8%8bid%e6%9f%a5%e7%9c%8b%e8%bf%9b%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18387\/","title":{"rendered":"linux\u6839\u636e\u8fdb\u7a0bid\u67e5\u770b\u8fdb\u7a0b"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u6839\u636e\u8fdb\u7a0b id \u67e5\u770b linux \u8fdb\u7a0b\u4fe1\u606f\uff1f\u67e5\u627e\u8981\u67e5\u770b\u7684\u8fdb\u7a0b\u7684 pid\u3002\u4f7f\u7528 ps -p pid \u547d\u4ee4\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\uff0c\u5305\u62ec cpu \u4f7f\u7528\u7387\u3001\u5185\u5b58\u5360\u7528\u3001\u8fdb\u7a0b\u72b6\u6001\u548c\u547d\u4ee4\u884c\u3002\u4f7f\u7528\u5176\u4ed6\u547d\u4ee4\u67e5\u770b\u7279\u5b9a\u4fe1\u606f\uff0c\u4f8b\u5982\uff1atop -p pid\uff1a\u5b9e\u65f6\u8fdb\u7a0b\u4fe1\u606fstrace -p pid\uff1a\u7cfb\u7edf\u8c03\u7528\u8ddf\u8e2alsof -p pid\uff1a\u6253\u5f00\u7684\u6587\u4ef6\u5217\u8868\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/17\/2024081718550334729.jpg\" class=\"aligncenter\" title=\"linux\u6839\u636e\u8fdb\u7a0bid\u67e5\u770b\u8fdb\u7a0b\u63d2\u56fe\" alt=\"linux\u6839\u636e\u8fdb\u7a0bid\u67e5\u770b\u8fdb\u7a0b\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u6839\u636e\u8fdb\u7a0b ID \u67e5\u770b Linux \u8fdb\u7a0b<\/strong><\/p>\n<p>\u83b7\u53d6 Linux \u8fdb\u7a0b\u7684\u4fe1\u606f\u662f\u7cfb\u7edf\u7ba1\u7406\u7684\u4e00\u4e2a\u5173\u952e\u65b9\u9762\u3002\u901a\u8fc7\u8fdb\u7a0b ID\uff08PID\uff09\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u67e5\u770b\u6709\u5173\u7279\u5b9a\u8fdb\u7a0b\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u4f8b\u5982 CPU \u4f7f\u7528\u7387\u3001\u548c\u6253\u5f00\u7684\u6587\u4ef6\u3002<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u67e5\u627e\u8fdb\u7a0b ID<\/strong><\/p>\n<p>\u786e\u5b9a\u8981\u67e5\u770b\u7684\u8fdb\u7a0b\u7684 PID\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4e4b\u4e00\uff1a<\/p>\n<pre># \u4f7f\u7528 ps \u547d\u4ee4\u83b7\u53d6\u8fdb\u7a0b\u5217\u8868\nps aux\n\n# \u4f7f\u7528 pidof \u547d\u4ee4\u83b7\u53d6\u7279\u5b9a\u8fdb\u7a0b\u7684 PID\npidof process_name<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u4f7f\u7528 ps \u547d\u4ee4\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6839\u636e PID \u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\uff1a<\/p>\n<pre>ps -p PID<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d PID \u662f\u60a8\u8981\u67e5\u770b\u7684\u8fdb\u7a0b\u7684\u8fdb\u7a0b ID\u3002<\/p>\n<p>\u547d\u4ee4\u8f93\u51fa\u5c06\u663e\u793a\u6709\u5173\u8fdb\u7a0b\u7684\u5404\u79cd\u4fe1\u606f\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>PID\uff1a<\/strong> \u8fdb\u7a0b ID<\/li>\n<li> <strong>USER\uff1a<\/strong> \u62e5\u6709\u8be5\u8fdb\u7a0b\u7684\u7528\u6237<\/li>\n<li> <strong>%CPU\uff1a<\/strong> CPU \u4f7f\u7528\u7387<\/li>\n<li> <strong>%MEM\uff1a<\/strong> \u5185\u5b58\u4f7f\u7528\u7387<\/li>\n<li> <strong>VSZ\uff1a<\/strong> \u865a\u62df\u5185\u5b58\u5927\u5c0f<\/li>\n<li> <strong>RSS\uff1a<\/strong> \u7269\u7406\u5185\u5b58\u5927\u5c0f<\/li>\n<li> <strong>STAT\uff1a<\/strong> \u8fdb\u7a0b\u72b6\u6001\uff08\u4f8b\u5982 R\uff08\u6b63\u5728\u8fd0\u884c\uff09\u6216 S\uff08\u7761\u7720\uff09\uff09<\/li>\n<li> <strong>START\uff1a<\/strong> \u8fdb\u7a0b\u542f\u52a8\u65f6\u95f4<\/li>\n<li> <strong>TIME\uff1a<\/strong> \u8fdb\u7a0b\u8fd0\u884c\u65f6\u95f4<\/li>\n<li> <strong>COMMAND\uff1a<\/strong> \u8fdb\u7a0b\u547d\u4ee4\u884c<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 3\uff1a\u4f7f\u7528\u5176\u4ed6\u547d\u4ee4\u67e5\u770b\u7279\u5b9a\u4fe1\u606f<\/strong><\/p>\n<p>\u9664\u4e86 ps \u547d\u4ee4\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u547d\u4ee4\u67e5\u770b\u7279\u5b9a\u4fe1\u606f\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>top -p PID\uff1a\u67e5\u770b\u5b9e\u65f6\u8fdb\u7a0b\u4fe1\u606f\uff0c\u5305\u62ec CPU \u548c\u5185\u5b58\u4f7f\u7528\u7387\u3002<\/li>\n<li>strace -p PID\uff1a\u8ddf\u8e2a\u8fdb\u7a0b\u7684\u7cfb\u7edf\u8c03\u7528\u3002<\/li>\n<li>lsof -p PID\uff1a\u5217\u51fa\u8fdb\u7a0b\u6253\u5f00\u7684\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u8981\u67e5\u770b PID \u4e3a 1234 \u7684\u8fdb\u7a0b\u7684\u4fe1\u606f\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>ps -p 1234<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u5c06\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND\nuser1     1234  0.1  0.1   1000k  500k tty1     R    14:30   0:00 \/bin\/bash<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6839\u636e\u8fdb\u7a0bid\u67e5\u770b\u8fdb\u7a0b\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\u6839\u636e\u8fdb\u7a0b id \u67e5\u770b linux \u8fdb\u7a0b\u4fe1\u606f\uff1f\u67e5\u627e\u8981\u67e5\u770b\u7684\u8fdb\u7a0b\u7684 pid\u3002\u4f7f\u7528 ps -p pid \u547d\u4ee4\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\uff0c\u5305\u62ec cpu \u4f7f\u7528\u7387\u3001\u5185\u5b58\u5360\u7528\u3001\u8fdb\u7a0b\u72b6\u6001\u548c\u547d\u4ee4\u884c\u3002\u4f7f\u7528\u5176\u4ed6\u547d\u4ee4\u67e5\u770b\u7279\u5b9a\u4fe1\u606f\uff0c\u4f8b\u5982\uff1atop -p pid\uff1a\u5b9e\u65f6\u8fdb\u7a0b\u4fe1\u606fstrace -p pid\uff1a\u7cfb\u7edf\u8c03\u7528\u8ddf\u8e2alsof -p pid\uff1a\u6253\u5f00\u7684\u6587\u4ef6\u5217\u8868 \u5982\u4f55\u6839\u636e\u8fdb\u7a0b ID \u67e5\u770b Linux \u8fdb\u7a0b \u83b7\u53d6 Linux \u8fdb\u7a0b\u7684\u4fe1\u606f\u662f\u7cfb\u7edf\u7ba1\u7406\u7684\u4e00\u4e2a\u5173\u952e\u65b9\u9762\u3002\u901a\u8fc7\u8fdb\u7a0b ID\uff08PID\uff09\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u67e5\u770b\u6709\u5173\u7279\u5b9a\u8fdb\u7a0b\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u4f8b\u5982 CPU \u4f7f\u7528\u7387\u3001\u548c\u6253\u5f00\u7684\u6587\u4ef6\u3002 \u6b65\u9aa4 1\uff1a\u67e5\u627e\u8fdb\u7a0b ID \u786e\u5b9a\u8981\u67e5\u770b\u7684\u8fdb\u7a0b\u7684 PID\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4e4b\u4e00\uff1a # \u4f7f\u7528 ps \u547d\u4ee4\u83b7\u53d6\u8fdb\u7a0b\u5217\u8868 ps aux # \u4f7f\u7528 pidof \u547d\u4ee4\u83b7\u53d6\u7279\u5b9a\u8fdb\u7a0b\u7684 PID pidof process_name \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 2\uff1a\u4f7f\u7528 ps \u547d\u4ee4\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6839\u636e PID \u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\uff1a [&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-18387","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18387","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=18387"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18387\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18387"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18387"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18387"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}