{"id":197892,"date":"2020-08-15T08:21:10","date_gmt":"2020-08-15T00:21:10","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=197892"},"modified":"2021-07-03T14:57:15","modified_gmt":"2021-07-03T06:57:15","slug":"linux-look-process","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-look-process.html","title":{"rendered":"\u5982\u4f55\u5728Linux\u4e2d\u67e5\u770b\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b"},"content":{"rendered":"

\u300aLinux\u5c31\u8be5\u8fd9\u4e48\u5b66\u300b - \u5fc5\u8bfb\u7684Linux\u7cfb\u7edf\u4e0e\u7ea2\u5e3dRHCE\u8ba4\u8bc1\u514d\u8d39\u81ea\u5b66\u4e66\u7c4d<\/strong><\/span><\/p>\n

\u514d\u8d39\u7535\u5b50\u7248\u4e0b\u8f7d\u5730\u5740\uff1ahttps:\/\/lrxjmw.cn\/book<\/a><\/strong><\/span><\/p>\n

\"\"<\/a><\/p>\n\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fdb\u7a0b\u662f\u4e00\u4e2a\u5176\u4e2d\u8fd0\u884c\u7740\u4e00\u4e2a\u6216\u591a\u4e2a\u7ebf\u7a0b\u7684\u5730\u5740\u7a7a\u95f4\u548c\u8fd9\u4e9b\u7ebf\u7a0b\u6240\u9700\u8981\u7684\u7cfb\u7edf\u8d44\u6e90\u3002\u5728Linux\u7cfb\u7edf\u4e2d\u6709\u5f88\u591a\u547d\u4ee4\u3002\u90a3\u4e48\u54ea\u4e9b\u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u6240\u6709\u8fd0\u884c\u4e2d\u7684\u8fdb\u7a0b\u5462\uff1f <\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4f60\u53ef\u4ee5\u4f7f\u7528ps\u547d\u4ee4\u3002\u5b83\u80fd\u663e\u793a\u5f53\u524d\u8fd0\u884c\u4e2d\u8fdb\u7a0b\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u5305\u62ec\u8fdb\u7a0b\u7684PID\u3002Linux\u548cUNIX\u90fd\u652f\u6301ps\u547d\u4ee4\uff0c\u663e\u793a\u6240\u6709\u8fd0\u884c\u4e2d\u8fdb\u7a0b\u7684\u76f8\u5173\u4fe1\u606f\u3002ps\u547d\u4ee4\u80fd\u63d0\u4f9b\u4e00\u4efd\u5f53\u524d\u8fdb\u7a0b\u7684\u5feb\u7167\u3002\u5982\u679c\u4f60\u60f3\u72b6\u6001\u53ef\u4ee5\u81ea\u52a8\u5237\u65b0\uff0c\u53ef\u4ee5\u4f7f\u7528top\u547d\u4ee4\u3002<\/p>\n

ps\u547d\u4ee4<\/strong><\/strong><\/span><\/div>\n

\u8f93\u5165\u4e0b\u9762\u7684ps\u547d\u4ee4\uff0c\u663e\u793a\u6240\u6709\u8fd0\u884c\u4e2d\u7684\u8fdb\u7a0b\uff1a<\/p>\n

# ps aux | less<\/pre>\n

\u5176\u4e2d\uff0c<\/p>\n

-A\uff1a\u663e\u793a\u6240\u6709\u8fdb\u7a0b<\/p>\n

a\uff1a\u663e\u793a\u7ec8\u7aef\u4e2d\u5305\u62ec\u5176\u5b83\u7528\u6237\u7684\u6240\u6709\u8fdb\u7a0b<\/p>\n

x\uff1a\u663e\u793a\u65e0\u63a7\u5236\u7ec8\u7aef\u7684\u8fdb\u7a0b<\/p>\n

\u4efb\u52a1\uff1a\u67e5\u770b\u7cfb\u7edf\u4e2d\u7684\u6bcf\u4e2a\u8fdb\u7a0b\u3002<\/strong><\/p>\n

# ps -A\r\n# ps -e<\/pre>\n

\u4efb\u52a1\uff1a\u67e5\u770b\u975eroot\u8fd0\u884c\u7684\u8fdb\u7a0b<\/strong><\/p>\n

# ps -U root -u root -N<\/pre>\n

\u4efb\u52a1\uff1a\u67e5\u770b\u7528\u6237vivek\u8fd0\u884c\u7684\u8fdb\u7a0b<\/strong><\/p>\n

# ps -u vivek<\/pre>\n
top\u547d\u4ee4<\/strong><\/strong><\/span><\/div>\n

top\u547d\u4ee4\u63d0\u4f9b\u4e86\u8fd0\u884c\u4e2d\u7cfb\u7edf\u7684\u52a8\u6001\u5b9e\u65f6\u89c6\u56fe\u3002\u5728\u547d\u4ee4\u63d0\u793a\u884c\u4e2d\u8f93\u5165top\uff1a<\/p>\n

# top<\/pre>\n

\u8f93\u51fa\uff1a<\/p>\n

\"\"<\/a><\/p>\n

<\/center>\u56fe1\uff1atop\u547d\u4ee4\uff1a\u663e\u793aLinux\u4efb\u52a1<\/p>\n

\u6309q\u9000\u51fa\uff0c\u6309h\u8fdb\u5165\u5e2e\u52a9\u3002<\/p>\n

\u663e\u793a\u8fdb\u7a0b\u7684\u6811\u72b6\u56fe<\/strong><\/strong><\/span><\/div>\n

pstree\u4ee5\u6811\u72b6\u663e\u793a\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u3002\u6811\u7684\u6839\u8282\u70b9\u4e3apid\u6216init\u3002\u5982\u679c\u6307\u5b9a\u4e86\u7528\u6237\u540d\uff0c\u8fdb\u7a0b\u6811\u5c06\u4ee5\u7528\u6237\u6240\u62e5\u6709\u7684\u8fdb\u7a0b\u4f5c\u4e3a\u6839\u8282\u70b9\u3002<\/p>\n

$ pstree<\/pre>\n

\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n

\"\"<\/a><\/p>\n

<\/center>\u56fe2\uff1apstree - \u663e\u793a\u8fdb\u7a0b\u7684\u6811\u72b6\u56fe<\/p>\n

\u4efb\u52a1\uff1a\u4f7f\u7528ps\u5217\u5370\u8fdb\u7a0b\u6811<\/strong><\/p>\n

# ps -ejH\r\n# ps axjf<\/pre>\n

\u4efb\u52a1\uff1a\u83b7\u5f97\u7ebf\u7a0b\u4fe1\u606f<\/strong><\/p>\n

\u8f93\u5165\u4e0b\u5217\u547d\u4ee4\uff1a<\/p>\n

# ps -eLf\r\n# ps axms<\/pre>\n

\u4efb\u52a1\uff1a\u83b7\u5f97\u5b89\u5168\u4fe1\u606f<\/strong><\/p>\n

\u8f93\u5165\u4e0b\u5217\u547d\u4ee4\uff1a<\/p>\n

# ps -eo euser,ruser,suser,fuser,f,comm,label\r\n# ps axZ\r\n# ps -eM<\/pre>\n

\u4efb\u52a1\uff1a\u5c06\u8fdb\u7a0b\u5feb\u7167\u50a8\u5b58\u5230\u6587\u4ef6\u4e2d<\/strong><\/p>\n

\u8f93\u5165\u4e0b\u5217\u547d\u4ee4\uff1a<\/p>\n

# top -b -n1 > \/tmp\/process.log<\/pre>\n

\u4f60\u4e5f\u53ef\u4ee5\u5c06\u7ed3\u679c\u901a\u8fc7\u90ae\u4ef6\u53d1\u7ed9\u81ea\u5df1\uff1a<\/p>\n

# top -b -n1 | mail -s 'Process snapshot' you@example.com<\/pre>\n

\u4efb\u52a1\uff1a\u67e5\u627e\u8fdb\u7a0b<\/strong><\/p>\n

\u4f7f\u7528pgrep\u547d\u4ee4\u3002pgrep\u80fd\u67e5\u627e\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\u5e76\u5217\u51fa\u7b26\u5408\u6761\u4ef6\u7684\u8fdb\u7a0bID\u3002\u4f8b\u5982\u663e\u793afirefox\u7684\u8fdb\u7a0bID\uff1a<\/p>\n

$ pgrep firefox<\/pre>\n

\u4e0b\u9762\u547d\u4ee4\u5c06\u663e\u793a\u8fdb\u7a0b\u540d\u4e3asshd\u3001\u6240\u6709\u8005\u4e3aroot\u7684\u8fdb\u7a0b\u3002<\/p>\n

$ pgrep -u root sshd<\/pre>\n
\u5411htop\u548catop\u8bf4hello<\/strong><\/strong><\/span><\/div>\n

htop\u662f\u4e00\u4e2a\u7c7b\u4f3ctop\u7684\u4ea4\u4e92\u5f0f\u8fdb\u7a0b\u67e5\u770b\u5de5\u5177\uff0c\u4f46\u662f\u53ef\u4ee5\u5782\u76f4\u548c\u6c34\u5e73\u6eda\u52a8\u6765\u67e5\u770b\u6240\u6709\u8fdb\u7a0b\u548c\u4ed6\u4eec\u7684\u547d\u4ee4\u884c\u3002\u8fdb\u7a0b\u7684\u76f8\u5173\u64cd\u4f5c(killing\uff0crenicing)\u4e0d\u9700\u8981\u8f93\u5165PID\u3002\u8981\u5b89\u88c5htop\u8f93\u5165\u547d\u4ee4\uff1a<\/p>\n

# apt-get install htop<\/pre>\n

\u6216<\/p>\n

# yum install htop<\/pre>\n

\u5728\u547d\u4ee4\u63d0\u793a\u884c\u4e2d\u8f93\u5165htop\uff1a<\/p>\n

# htop<\/pre>\n

\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n

\"\"<\/a><\/p>\n

<\/center>\u56fe3\uff1ahtop - Interactive Linux \/ UNIX process viewer<\/p>\n
atop\u5de5\u5177<\/strong><\/strong><\/span><\/div>\n

atop\u662f\u4e00\u4e2a\u7528\u6765\u67e5\u770bLinux\u7cfb\u7edf\u8d1f\u8f7d\u7684\u4ea4\u4e92\u5f0f\u76d1\u63a7\u5de5\u5177\u3002\u5b83\u80fd\u5c55\u73b0\u7cfb\u7edf\u5c42\u7ea7\u7684\u5173\u952e\u786c\u4ef6\u8d44\u6e90(\u4ece\u6027\u80fd\u89d2\u5ea6)\u7684\u4f7f\u7528\u60c5\u51b5\uff0c\u5982CPU\u3001\u5185\u5b58\u3001\u786c\u76d8\u548c\u7f51\u7edc\u3002<\/p>\n

\u5b83\u4e5f\u53ef\u4ee5\u6839\u636e\u8fdb\u7a0b\u5c42\u7ea7\u7684CPU\u548c\u5185\u5b58\u8d1f\u8f7d\u663e\u793a\u54ea\u4e2a\u8fdb\u7a0b\u9020\u6210\u4e86\u7279\u5b9a\u7684\u8d1f\u8f7d;\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\u5185\u6838\u8865\u4e01\u53ef\u4ee5\u663e\u793a\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u786c\u76d8\u548c\u7f51\u7edc\u8d1f\u8f7d\u3002\u8f93\u5165\u4e0b\u9762\u7684\u547d\u4ee4\u542f\u52a8atop\uff1a<\/p>\n

# atop<\/pre>\n

\u8f93\u51fa\u793a\u4f8b\uff1a<\/p>\n

\"\"<\/a><\/p>\n

\u7ea2\u5e3dRHCE\u8ba4\u8bc1\u8003\u9898\u8bb2\u89e3\uff1ahttps:\/\/lrxjmw.cn\/redhat-certificate<\/a><\/span><\/strong><\/p>\n

\"\u7b2c0\u7ae0<\/p>\n","protected":false},"excerpt":{"rendered":"

\u300aLinux\u5c31\u8be5\u8fd9\u4e48\u5b66\u300b – \u5fc5\u8bfb\u7684Linux\u7cfb\u7edf\u4e0e\u7ea2\u5e3dRHCE\u8ba4\u8bc1\u514d\u8d39\u81ea\u5b66\u4e66\u7c4d \u514d\u8d39\u7535\u5b50\u7248\u4e0b\u8f7d\u5730\u5740\uff1ahttp […]<\/p>\n","protected":false},"author":643,"featured_media":198066,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-197892","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/197892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=197892"}],"version-history":[{"count":10,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/197892\/revisions"}],"predecessor-version":[{"id":222155,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/197892\/revisions\/222155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/198066"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=197892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=197892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=197892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}