{"id":224744,"date":"2021-08-29T08:43:13","date_gmt":"2021-08-29T00:43:13","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=224744"},"modified":"2021-08-20T14:47:26","modified_gmt":"2021-08-20T06:47:26","slug":"linux-batch-mode-top","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-batch-mode-top.html","title":{"rendered":"\u5982\u4f55\u5728 Linux \u4e2d\u4ee5\u811a\u672c\u6a21\u5f0f\u8fd0\u884c Top"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\ntop \u547d\u4ee4\u7528\u4e8e\u663e\u793a Linux \u7cfb\u7edf\u4e2d\u7684\u5b9e\u65f6\u5904\u7406\u6d3b\u52a8\uff0c\u4ee5\u53ca\u5185\u6838\u7ba1\u7406\u7684\u4efb\u52a1\u3002\u5b83\u5c06\u663e\u793a CPU \u548c\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u53ca\u5176\u4ed6\u4fe1\u606f\uff0c\u4f8b\u5982\u6b63\u5728\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002\u53ef\u4ee5\u5229\u7528\u811a\u672c\u6a21\u5f0f\u7684\u9009\u9879\u5c06top\u547d\u4ee4\u8f93\u51fa\u4f20\u8f93\u5230\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u6216\u6587\u4ef6\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u4f7f\u7528 Top \u547d\u4ee4\u811a\u672c\u6a21\u5f0f\u7684\u65b9\u6cd5<\/strong><\/div>\n

\u5728 Centos8 \u4e2d\uff0c\u6211\u4eec\u6267\u884c\u672c\u6587\u4e2d\u7684\u547d\u4ee4\u3002\u4e0b\u9762\u547d\u4ee4\u6309\u7167 CPU \u4f7f\u7528\u7387\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u5e76\u6253\u5370\u547d\u4ee4\u4e2d\u6307\u5b9a\u7684\u524d 20 \u884c\u3002<\/p>\n

\r\n[root@localhost ~]# top -bc -n 1 | head -20\r\ntop - 22:23:02 up 6 days, 12:36,  2 users,  load average: 0.00, 0.00, 0.00\r\nTasks: 186 total,   2 running, 184 sleeping,   0 stopped,   0 zombie\r\n%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st\r\nMiB Mem :   1792.0 total,    886.5 free,    277.0 used,    628.4 buff\/cache\r\nMiB Swap:   2048.0 total,   2048.0 free,      0.0 used.   1333.1 avail Mem \r\n\r\n    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND\r\n      1 root      20   0  176848  10824   8116 S   0.0   0.6   0:04.50 \/usr\/lib\/systemd\/systemd --switch+\r\n      2 root      20   0       0      0      0 S   0.0   0.0   0:00.01 [kthreadd]\r\n      3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 [rcu_gp]\r\n      4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 [rcu_par_gp]\r\n      6 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 [kworker\/0:0H-kblockd]\r\n      9 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 [mm_percpu_wq]\r\n     10 root      20   0       0      0      0 S   0.0   0.0   0:00.70 [ksoftirqd\/0]\r\n     11 root      20   0       0      0      0 I   0.0   0.0   0:02.64 [rcu_sched]\r\n     12 root      rt   0       0      0      0 S   0.0   0.0   0:00.00 [migration\/0]\r\n     13 root      rt   0       0      0      0 S   0.0   0.0   0:00.45 [watchdog\/0]\r\n     14 root      20   0       0      0      0 S   0.0   0.0   0:00.00 [cpuhp\/0]\r\n     16 root      20   0       0      0      0 S   0.0   0.0   0:00.00 [kdevtmpfs]\r\n     17 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 [netns]\r\n<\/pre>\n

\"\"
\n\u5982\u679c\u8981\u6309\u7167\u5185\u5b58\u4f7f\u7528\u987a\u5e8f\u6392\u5e8f\uff0c\u9700\u8981\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\uff1a<\/p>\n

\r\n[root@localhost ~]# top -bc -o +%MEM -n 1 | head -n 20\r\ntop - 22:26:01 up 6 days, 12:39,  2 users,  load average: 0.00, 0.00, 0.00\r\nTasks: 187 total,   1 running, 186 sleeping,   0 stopped,   0 zombie\r\n%Cpu(s):  5.9 us,  5.9 sy,  0.0 ni, 88.2 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st\r\nMiB Mem :   1792.0 total,    834.6 free,    329.0 used,    628.4 buff\/cache\r\nMiB Swap:   2048.0 total,   2048.0 free,      0.0 used.   1281.2 avail Mem \r\n\r\n    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND\r\n  22531 root      20   0  615344  75672  25780 S   0.0   4.1   0:00.80 node \/usr\/local\/bin\/evilscan 192.+\r\n    968 root      20   0  413544  35488  34188 S   0.0   1.9   0:02.32 \/usr\/libexec\/sssd\/sssd_nss --uid +\r\n    971 root      20   0  462996  34880  14700 S   0.0   1.9   0:00.65 \/usr\/libexec\/platform-python -s \/+\r\n    997 root      20   0  612436  28888  14600 S   0.0   1.6   0:35.22 \/usr\/libexec\/platform-python -Es +\r\n    948 polkitd   20   0 1772752  23756  16596 S   0.0   1.3   0:00.30 \/usr\/lib\/polkit-1\/polkitd --no-de+\r\n    980 root      20   0  753768  18484  15908 S   0.0   1.0   0:05.09 \/usr\/sbin\/NetworkManager --no-dae+\r\n    813 root      20   0  118756  14588  13040 S   0.0   0.8   0:04.79 \/usr\/lib\/systemd\/systemd-journald\r\n    966 root      20   0  402088  12008   9900 S   0.0   0.7   0:01.93 \/usr\/libexec\/sssd\/sssd_be --domai+\r\n    950 root      20   0  395652  11736  10132 S   0.0   0.6   0:00.34 \/usr\/sbin\/sssd -i --logger=files\r\n      1 root      20   0  176848  10824   8116 S   0.0   0.6   0:04.50 \/usr\/lib\/systemd\/systemd --switch+\r\n   6620 root      20   0  152796  10216   8992 S   0.0   0.6   0:00.01 sshd: root [priv]\r\n    840 root      20   0  115684   9876   7312 S   0.0   0.5   0:00.47 \/usr\/lib\/systemd\/systemd-udevd\r\n   6623 root      20   0   93708   9500   8112 S   0.0   0.5   0:00.04 \/usr\/lib\/systemd\/systemd --user\r\n<\/pre>\n

\"\"
\n\u4e0a\u9762\u547d\u4ee4\u4e2d\u5173\u4e8etop<\/code>\u547d\u4ee4\u4f7f\u7528\u7684\u9009\u9879\u89e3\u91ca\u5982\u4e0b\uff1a<\/p>\n

    \n
  • -b<\/code>: \u8fd0\u884c\u811a\u672c\u6a21\u5f0f<\/li>\n
  • -c<\/code>: \u663e\u793aCOMMAND\u5217\u4e2d\u547d\u4ee4\u7684\u5b8c\u6574\u8def\u5f84<\/li>\n
  • -n<\/code>: \u6307\u5b9atop\u5728\u7ed3\u675f\u4e4b\u524d\u5e94\u8be5\u4ea7\u751f\u7684\u6700\u5927\u8fed\u4ee3\u6570\u3002<\/li>\n
  • -o<\/code>: \u5b9a\u4e49\u4e86\u6309\u7167\u54ea\u4e2a\u5b57\u6bb5\u6392\u5e8f\u3002<\/li>\n<\/ul>\n

    \u5728\u6279\u5904\u7406\u6a21\u5f0f\u4e0b\uff0c\u4f7f\u7528 top \u547d\u4ee4\u6839\u636e\u8fdb\u7a0b\u7684\u4f7f\u7528\u7684\u65f6\u95f4\u6392\u5217\u6570\u636e\u3002\u5b83\u663e\u793a\u8fdb\u7a0b\u81ea\u542f\u52a8\u4ee5\u6765\u6d88\u8017\u7684 CPU \u65f6\u95f4\u603b\u91cf\u3002\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u67e5\u770b\uff1a<\/p>\n

    \r\n[root@localhost ~]# top -bc -o TIME+ -n 1 | head -n 20\r\ntop - 22:31:20 up 6 days, 12:44,  2 users,  load average: 0.00, 0.04, 0.01\r\nTasks: 187 total,   1 running, 186 sleeping,   0 stopped,   0 zombie\r\n%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st\r\nMiB Mem :   1792.0 total,    843.4 free,    320.1 used,    628.4 buff\/cache\r\nMiB Swap:   2048.0 total,   2048.0 free,      0.0 used.   1290.0 avail Mem \r\n\r\n    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND\r\n    997 root      20   0  612436  28888  14600 S   0.0   1.6   0:35.24 \/usr\/libexec\/platform-python -Es +\r\n    946 root      20   0  160120   6460   5656 S   0.0   0.4   0:06.08 \/sbin\/rngd -f\r\n    980 root      20   0  753768  18484  15908 S   0.0   1.0   0:05.10 \/usr\/sbin\/NetworkManager --no-dae+\r\n    813 root      20   0  118756  14588  13040 S   0.0   0.8   0:04.79 \/usr\/lib\/systemd\/systemd-journald\r\n      1 root      20   0  176848  10824   8116 S   0.0   0.6   0:04.50 \/usr\/lib\/systemd\/systemd --switch+\r\n    727 root      20   0       0      0      0 S   0.0   0.0   0:02.77 [xfsaild\/dm-0]\r\n     11 root      20   0       0      0      0 I   0.0   0.0   0:02.65 [rcu_sched]\r\n    968 root      20   0  413544  35488  34188 S   0.0   1.9   0:02.32 \/usr\/libexec\/sssd\/sssd_nss --uid +\r\n    966 root      20   0  402088  12008   9900 S   0.0   0.7   0:01.93 \/usr\/libexec\/sssd\/sssd_be --domai+\r\n    954 chrony    20   0   29444   2652   2400 S   0.0   0.1   0:01.16 \/usr\/sbin\/chronyd\r\n    945 dbus      20   0   74704   5896   5096 S   0.0   0.3   0:01.15 \/usr\/bin\/dbus-daemon --system --a+\r\n     24 root      39  19       0      0      0 S   0.0   0.0   0:01.13 [khugepaged]\r\n     10 root      20   0       0      0      0 S   0.0   0.0   0:00.79 [ksoftirqd\/0]\r\n<\/pre>\n

    \"\"
    \n\u4e0b\u9762\u53ef\u4ee5\u5c06top\u7684\u8f93\u51fa\u7ed3\u679c\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff1a<\/p>\n

    \r\n[root@localhost ~]# top -bc | head -30 > top-information.txt\r\n<\/pre>\n

    \"\"<\/p>\n

    \u603b\u7ed3<\/strong><\/div>\n

    top \u547d\u4ee4\u7528\u4e8e\u663e\u793a Linux \u7cfb\u7edf\u4e2d\u7684\u5b9e\u65f6\u5904\u7406\u6d3b\u52a8\uff0c\u4ee5\u53ca\u5185\u6838\u7ba1\u7406\u7684\u4efb\u52a1\u3002\u5b83\u5c06\u663e\u793a CPU \u548c\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u53ca\u5176\u4ed6\u4fe1\u606f\uff0c\u4f8b\u5982\u6b63\u5728\u8fd0\u884c\u7684\u7a0b\u5e8f\u3002\u53ef\u4ee5\u5229\u7528\u811a\u672c\u6a21\u5f0f\u7684\u9009\u9879\u5c06top\u547d\u4ee4\u8f93\u51fa\u4f20\u8f93\u5230\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u6216\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u5728 Centos8 \u4e2d\uff0c\u6211\u4eec\u6267\u884c\u672c\u6587\u4e2d\u7684\u547d\u4ee4\u3002\u4e0b\u9762\u547d\u4ee4\u6309\u7167 CPU \u4f7f\u7528\u7387\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u5e76\u6253\u5370\u547d\u4ee4\u4e2d\u6307\u5b9a\u7684\u524d […]<\/p>\n","protected":false},"author":309,"featured_media":224745,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-224744","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\/224744","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\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=224744"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/224744\/revisions"}],"predecessor-version":[{"id":224751,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/224744\/revisions\/224751"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/224745"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=224744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=224744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=224744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}