Terminal

啟動 top 命令立即顯示所有核心

  • September 10, 2020

我知道一旦你top按下1,你就可以看到每個處理器上的負載(讓我們忘記多執行緒問題),如果你按下s,你可以配置刷新時間。

如何將此選項放在啟動命令中?

我正在嘗試使用

$ top -b -p $(pidof myprocess) > top.log

但我想看到我的四個處理器和更高的刷新率。

Linuxtop支持配置文件 ( ~/.toprc),它也可以從執行配置中寫入:

  • 開始top
  • 啟用您想要的選項(顏色、更新頻率、排序順序、顯示的統計資訊,…)
  • 命中W(即 shift+w)

下次執行top時,它將讀取您的配置並將其預設值更改為您所要求的。

顯示top manpageStartup Defaultscommandline. Cpu顯示器不是其中之一。

  Startup Defaults
  The following startup defaults assume no configuration file, thus no user customizations.  Even so, items shown with an asterisk (’*’) could be overridden  through  the  command-
  line.

      Global_defaults
         ’A’ - Alt display      Off (full-screen)
       * ’d’ - Delay time       3.0 seconds
         ’I’ - Irix mode        On  (no, ’solaris’ smp)
       * ’p’ - PID monitoring   Off
       * ’s’ - Secure mode      Off (unsecured)
         ’B’ - Bold disable     Off
      Summary_Area_defaults
         ’l’ - Load Avg/Uptime  On  (thus program name)
         ’t’ - Task/Cpu states  On  (1+1 lines, see ’1’)
         ’m’ - Mem/Swap usage   On  (2 lines worth)
         ’1’ - Single Cpu       On  (thus 1 line if smp)
      Task_Area_defaults
         ’b’ - Bold hilite      On  (not ’reverse’)
       * ’c’ - Command line     Off (name, not cmdline)
       * ’H’ - Threads          Off (show all threads)
       * ’i’ - Idle tasks       On  (show all tasks)
         ’R’ - Reverse sort     On  (pids high-to-low)
       * ’S’ - Cumulative time  Off (no, dead children)
         ’x’ - Column hilite    Off (no, sort field)
         ’y’ - Row hilite       On  (yes, running tasks)
         ’z’ - color/mono       Off (no, colors)

這可以使用top配置文件來完成。來自top manpage

  5b. PERSONAL Configuration File
  This file is written as ’$HOME/.your-name-4-top’ + ’rc’.  Use the ’W’ interactive command to create it or update it.

創建開始top顯示所有處理器的配置文件的步驟:

1. Start `top`.
2. Toggle display of all CPUs (press 1).
3. Press `d` or `s` and set new delay (default=3.0 seconds).  (This can be set on the `commandline`.  See the `Startup Defaults` above.
4. Press Shift+W.  Notice message 'Wrote configuration to '/home/youruser/.toprc'.
5. Quit `top`.
6. Start `top`.  Until you rewrite the `top` configuration file with a different option (Step #3), it will start with all CPUs showing.

引用自:https://unix.stackexchange.com/questions/256377