加入收藏 | 设为首页 | 会员中心 | 我要投稿 南京站长网 (https://www.025zz.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Windows > 正文

如何在批处理模式下运行top命令

发布时间:2019-10-28 14:26:01 所属栏目:Windows 来源:Magesh Maruthamuthu
导读:副标题#e# top 命令 是每个人都在使用的用于 监控 Linux 系统性能 的最好的命令。你可能已经知道 top 命令的绝大部分操作,除了很少的几个操作,如果我没错的话,批处理模式就是其中之一。 大部分的脚本编写者和开发人员都知道这个,因为这个操作主要就是用
副标题[/!--empirenews.page--]

如何在批处理模式下运行top命令

top 命令 是每个人都在使用的用于 监控 Linux 系统性能 的最好的命令。你可能已经知道 top 命令的绝大部分操作,除了很少的几个操作,如果我没错的话,批处理模式就是其中之一。

大部分的脚本编写者和开发人员都知道这个,因为这个操作主要就是用来编写脚本。

如果你不了解这个,不用担心,我们将在这里介绍它。

什么是 top 命令的批处理模式

批处理模式允许你将 top 命令的输出发送至其他程序或者文件中。

在这个模式中,top 命令将不会接收输入并且持续运行,直到迭代次数达到你用 -n 选项指定的次数为止。

如果你想解决 Linux 服务器上的任何性能问题,你需要正确的 理解 top 命令的输出。

1) 如何在批处理模式下运行 top 命令

默认地,top 命令按照 CPU 的使用率来排序输出结果,所以当你在批处理模式中运行以下命令时,它会执行同样的操作并打印前 35 行:

  1. # top -bc | head -35
  2.  
  3. top - 06:41:14 up 8 days, 20:24, 1 user, load average: 0.87, 0.77, 0.81
  4. Tasks: 139 total, 1 running, 136 sleeping, 0 stopped, 2 zombie
  5. %Cpu(s): 0.0 us, 3.2 sy, 0.0 ni, 96.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
  6. KiB Mem : 3880940 total, 1595932 free, 886736 used, 1398272 buff/cache
  7. KiB Swap: 1048572 total, 514640 free, 533932 used. 2648472 avail Mem
  8.  
  9. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  10. 1 root 20 0 191144 2800 1596 S 0.0 0.1 5:43.63 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
  11. 2 root 20 0 0 0 0 S 0.0 0.0 0:00.32 [kthreadd]
  12. 3 root 20 0 0 0 0 S 0.0 0.0 0:28.10 [ksoftirqd/0]
  13. 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/0:0H]
  14. 7 root rt 0 0 0 0 S 0.0 0.0 0:33.96 [migration/0]
  15. 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 [rcu_bh]
  16. 9 root 20 0 0 0 0 S 0.0 0.0 63:05.12 [rcu_sched]
  17. 10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [lru-add-drain]
  18. 11 root rt 0 0 0 0 S 0.0 0.0 0:08.79 [watchdog/0]
  19. 12 root rt 0 0 0 0 S 0.0 0.0 0:08.82 [watchdog/1]
  20. 13 root rt 0 0 0 0 S 0.0 0.0 0:44.27 [migration/1]
  21. 14 root 20 0 0 0 0 S 0.0 0.0 1:22.45 [ksoftirqd/1]
  22. 16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kworker/1:0H]
  23. 18 root 20 0 0 0 0 S 0.0 0.0 0:00.01 [kdevtmpfs]
  24. 19 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [netns]
  25. 20 root 20 0 0 0 0 S 0.0 0.0 0:01.35 [khungtaskd]
  26. 21 root 0 -20 0 0 0 S 0.0 0.0 0:00.02 [writeback]
  27. 22 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kintegrityd]
  28. 23 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [bioset]
  29. 24 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kblockd]
  30. 25 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [md]
  31. 26 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [edac-poller]
  32. 33 root 20 0 0 0 0 S 0.0 0.0 1:19.07 [kswapd0]
  33. 34 root 25 5 0 0 0 S 0.0 0.0 0:00.00 [ksmd]
  34. 35 root 39 19 0 0 0 S 0.0 0.0 0:12.80 [khugepaged]
  35. 36 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [crypto]
  36. 44 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kthrotld]
  37. 46 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 [kmpath_rdacd]

2) 如何在批处理模式下运行 top 命令并按内存使用率排序结果

(编辑:南京站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读