{"id":18370,"date":"2024-11-18T11:37:03","date_gmt":"2024-11-18T03:37:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18370\/"},"modified":"2024-11-18T11:37:03","modified_gmt":"2024-11-18T03:37:03","slug":"linux%e6%9f%a5%e7%9c%8b%e8%bf%9b%e7%a8%8b%e6%97%b6%e9%97%b4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18370\/","title":{"rendered":"linux\u67e5\u770b\u8fdb\u7a0b\u65f6\u95f4"},"content":{"rendered":"<blockquote><p>\n  \u5728 linux \u7cfb\u7edf\u4e2d\uff0c\u6709\u4ee5\u4e0b\u65b9\u6cd5\u67e5\u770b\u8fdb\u7a0b\u65f6\u95f4\uff1a\u4f7f\u7528 ps \u547d\u4ee4\uff08\u663e\u793a\u8fdb\u7a0b id \u548c\u5df2\u7528\u65f6\u95f4\uff09\uff1a$ ps -eo pid,etime\u4f7f\u7528 uptime \u547d\u4ee4\uff08\u663e\u793a\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4\uff09\uff1a$ uptime\u4f7f\u7528 top \u547d\u4ee4\uff08\u6309\u7528\u65f6\u6392\u5e8f\u8fdb\u7a0b\uff09\uff1a$ top -t\u4f7f\u7528 pidstat \u547d\u4ee4\uff08\u663e\u793a\u8be6\u7ec6\u6027\u80fd\u7edf\u8ba1\u4fe1\u606f\uff09\uff1a$ pidstat -d -p\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/17\/2024081718373828979.jpg\" class=\"aligncenter\" title=\"linux\u67e5\u770b\u8fdb\u7a0b\u65f6\u95f4\u63d2\u56fe\" alt=\"linux\u67e5\u770b\u8fdb\u7a0b\u65f6\u95f4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Linux \u4e2d\u67e5\u770b\u8fdb\u7a0b\u65f6\u95f4<\/strong><\/p>\n<p>\u67e5\u770b\u8fdb\u7a0b\u7684\u8fd0\u884c\u65f6\u95f4\u5bf9\u4e8e\u6027\u80fd\u5206\u6790\u548c\u6545\u969c\u6392\u9664\u81f3\u5173\u91cd\u8981\u3002\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u547d\u4ee4\u5b9e\u73b0\u8fd9\u4e00\u76ee\u7684\u3002<\/p>\n<p><strong>1. \u4f7f\u7528 ps \u547d\u4ee4<\/strong><\/p>\n<p>ps \u547d\u4ee4\u662f\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\u7684\u5e38\u7528\u5de5\u5177\u3002\u5b83\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528\uff0c\u5e76\u63d0\u4f9b\u4ee5\u4e0b\u9009\u9879\uff1a<\/p>\n<ul>\n<li>-p \uff1a\u6307\u5b9a\u7279\u5b9a\u8fdb\u7a0b ID\u3002 <\/li>\n<li>-e\uff1a\u663e\u793a\u6240\u6709\u8fdb\u7a0b\u3002<\/li>\n<li>-eo pid,etime\uff1a\u663e\u793a\u8fdb\u7a0b ID \u548c\u8fd0\u884c\u65f6\u95f4\uff08\u5df2\u7528\u65f6\u95f4\uff09\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>$ ps -eo pid,etime\nPID   ELAPSED\n2832  00:31:36\n3062  00:01:15\n3707  00:00:00<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 uptime \u547d\u4ee4<\/strong><\/p>\n<p>uptime \u547d\u4ee4\u663e\u793a\u7cfb\u7edf\u7edf\u8ba1\u4fe1\u606f\uff0c\u5305\u62ec\u5f53\u524d\u65f6\u95f4\u548c\u7cfb\u7edf\u5df2\u8fd0\u884c\u65f6\u95f4\u3002\u5b83\u8fd8\u53ef\u4ee5\u63d0\u4f9b\u6709\u5173\u8fdb\u7a0b\u603b\u6570\u548c\u5e73\u5747\u8d1f\u8f7d\u7684\u4fe1\u606f\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>$ uptime\n16:02:03 up 17 days, 17:59,  4 users,  load average: 2.31, 2.42, 2.40<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528 top \u547d\u4ee4<\/strong><\/p>\n<p>top \u547d\u4ee4\u63d0\u4f9b\u5b9e\u65f6\u7684\u8fdb\u7a0b\u4fe1\u606f\u89c6\u56fe\u3002\u5b83\u53ef\u4ee5\u6309 CPU \u4f7f\u7528\u7387\u3001\u5185\u5b58\u4f7f\u7528\u7387\u6216\u5176\u4ed6\u6307\u6807\u5bf9\u8fdb\u7a0b\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p>\u8981\u67e5\u770b\u8fdb\u7a0b\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u8bf7\u6309 F \u952e\u8fdb\u5165\u5168\u5c4f\u6a21\u5f0f\uff0c\u7136\u540e\u6309 t \u952e\u5bf9\u8fdb\u7a0b\u6309\u7528\u65f6\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>$ top -t\nPID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND\n1066 root      20   0  1706m  55m 1012 S  2.5  0.6   1:07.29 mysqld\n7576 root      20   0   280m  17m  716 S  0.0  0.2   0:00.00 rsyslogd\n9982 user      20   0  1404m 212m  816 S  1.0  2.3   0:00.05 python3<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u4f7f\u7528 pidstat \u547d\u4ee4<\/strong><\/p>\n<p>pidstat \u547d\u4ee4\u63d0\u4f9b\u6709\u5173\u8fdb\u7a0b\u7684\u8be6\u7ec6\u6027\u80fd\u7edf\u8ba1\u4fe1\u606f\uff0c\u5305\u62ec CPU \u4f7f\u7528\u7387\u3001\u5185\u5b58\u4f7f\u7528\u7387\u548c I\/O \u6d3b\u52a8\u3002<\/p>\n<p>\u8981\u67e5\u770b\u8fdb\u7a0b\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u8bf7\u4f7f\u7528 -p \u9009\u9879\u6307\u5b9a\u8fdb\u7a0b ID\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>$ pidstat -d -p 1066 1 5\nLinux 5.10.0-1040-azure (buildd@lcy01-amd64-016) (x86_64)\n10:40:30 pm        CPU      %usr   %system %guest    %wait    %idle\n10:40:31 pm        all    98.06    1.94     0.00    0.00    0.00\n               usr    97.99    2.01     0.00    0.00    0.00\n               sys     0.07    0.00     0.00    0.00    0.00\n               wai     0.00    0.00     0.00    0.00    0.00\n               idl     0.00    0.00     0.00    0.00    0.00\n10:40:32 pm        all    97.93    2.07     0.00    0.00    0.00\n               usr    97.93    1.99     0.01    0.00    0.00\n               sys     0.00    0.08     0.00    0.00    0.00\n               wai     0.00    0.00     0.00    0.00    0.00\n               idl     0.00    0.00     0.00    0.00    0.00\nProcess 1066 (mysqld),  98.06% usr,  1.94% sys, 0.00% guest, 0.00% wait, 0.00% idle<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e0a\u8ff0\u547d\u4ee4\u5c06\u6bcf\u79d2\u66f4\u65b0\u4e00\u6b21\u8fdb\u7a0b\u7edf\u8ba1\u4fe1\u606f\uff0c\u6301\u7eed 5 \u79d2\u3002\u60a8\u53ef\u4ee5\u5728 TIME+ \u5b57\u6bb5\u4e2d\u770b\u5230\u8fdb\u7a0b\u7684\u5f53\u524d\u8fd0\u884c\u65f6\u95f4\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u67e5\u770b\u8fdb\u7a0b\u65f6\u95f4\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>\u5728 linux \u7cfb\u7edf\u4e2d\uff0c\u6709\u4ee5\u4e0b\u65b9\u6cd5\u67e5\u770b\u8fdb\u7a0b\u65f6\u95f4\uff1a\u4f7f\u7528 ps \u547d\u4ee4\uff08\u663e\u793a\u8fdb\u7a0b id \u548c\u5df2\u7528\u65f6\u95f4\uff09\uff1a$ ps -eo pid,etime\u4f7f\u7528 uptime \u547d\u4ee4\uff08\u663e\u793a\u7cfb\u7edf\u8fd0\u884c\u65f6\u95f4\uff09\uff1a$ uptime\u4f7f\u7528 top \u547d\u4ee4\uff08\u6309\u7528\u65f6\u6392\u5e8f\u8fdb\u7a0b\uff09\uff1a$ top -t\u4f7f\u7528 pidstat \u547d\u4ee4\uff08\u663e\u793a\u8be6\u7ec6\u6027\u80fd\u7edf\u8ba1\u4fe1\u606f\uff09\uff1a$ pidstat -d -p \u5982\u4f55\u5728 Linux \u4e2d\u67e5\u770b\u8fdb\u7a0b\u65f6\u95f4 \u67e5\u770b\u8fdb\u7a0b\u7684\u8fd0\u884c\u65f6\u95f4\u5bf9\u4e8e\u6027\u80fd\u5206\u6790\u548c\u6545\u969c\u6392\u9664\u81f3\u5173\u91cd\u8981\u3002\u5728 Linux \u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u547d\u4ee4\u5b9e\u73b0\u8fd9\u4e00\u76ee\u7684\u3002 1. \u4f7f\u7528 ps \u547d\u4ee4 ps \u547d\u4ee4\u662f\u67e5\u770b\u8fdb\u7a0b\u4fe1\u606f\u7684\u5e38\u7528\u5de5\u5177\u3002\u5b83\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528\uff0c\u5e76\u63d0\u4f9b\u4ee5\u4e0b\u9009\u9879\uff1a -p \uff1a\u6307\u5b9a\u7279\u5b9a\u8fdb\u7a0b ID\u3002 -e\uff1a\u663e\u793a\u6240\u6709\u8fdb\u7a0b\u3002 -eo pid,etime\uff1a\u663e\u793a\u8fdb\u7a0b ID \u548c\u8fd0\u884c\u65f6\u95f4\uff08\u5df2\u7528\u65f6\u95f4\uff09\u3002 \u4f8b\u5982\uff1a $ ps -eo pid,etime PID ELAPSED 2832 00:31:36 3062 00:01:15 3707 00:00:00 [&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-18370","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18370","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=18370"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18370\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}