Linux 中的 ps 实用程序(procps),如何检查使用哪个 CPU

发布于 2024-11-02 15:49:21 字数 1827 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陪你搞怪i 2024-11-09 15:49:21

ps(1) 手册页显示您可以使用 psr 字段:

 psr 当前分配给进程的 PSR 处理器。
$ ps -o pid,psr,comm
  PID PSR COMMAND
 7871   1 bash
 9953   3 ps

或者您可以使用 cpuid 字段,它可以执行相同的操作。

$ ps -o pid,cpuid,comm
  PID CPUID COMMAND
 7871     1 bash
10746     3 ps

使用两个名称的原因是为了与 Solaris (psr) 和 NetBSD/OpenBSDcpuid)。

要也获取线程,请添加 -L 选项(如果使用 -o,则添加 lwp 字段)。

没有线程:

$ ps -U $USER -o pid,psr,comm | egrep 'chromi|PID' | head -4
  PID PSR COMMAND
 6457   3 chromium-browse
 6459   0 chromium-browse
 6461   2 chromium-browse

有线程:

$ ps -U $USER -L -o pid,lwp,psr,comm | egrep 'chromi|PID' | head -4
  PID   LWP PSR COMMAND
 6457  6457   3 chromium-browse
 6457  6464   1 chromium-browse
 6457  6465   2 chromium-browse

还有一个未记录的 -P 选项,它将 psr 添加到普通字段:

$ ps -U $USER -LP | egrep 'chromi|PID' | head -4
  PID   LWP PSR TTY          TIME CMD
 6457  6457   3 ?        00:01:19 chromium-browse
 6457  6464   1 ?        00:00:00 chromium-browse
 6457  6465   2 ?        00:00:00 chromium-browse

The ps(1) man page says you can use the psr field:

   psr        PSR     processor that process is currently assigned to.
$ ps -o pid,psr,comm
  PID PSR COMMAND
 7871   1 bash
 9953   3 ps

Or you can use the cpuid field, which does the same thing.

$ ps -o pid,cpuid,comm
  PID CPUID COMMAND
 7871     1 bash
10746     3 ps

The reason for two names is for compatibility with Solaris (psr) and NetBSD/OpenBSD (cpuid).

To get threads too, add the -L option (and the lwp field if you are using -o).

Without threads:

$ ps -U $USER -o pid,psr,comm | egrep 'chromi|PID' | head -4
  PID PSR COMMAND
 6457   3 chromium-browse
 6459   0 chromium-browse
 6461   2 chromium-browse

With threads:

$ ps -U $USER -L -o pid,lwp,psr,comm | egrep 'chromi|PID' | head -4
  PID   LWP PSR COMMAND
 6457  6457   3 chromium-browse
 6457  6464   1 chromium-browse
 6457  6465   2 chromium-browse

There's also an undocumented -P option, which adds psr to the normal fields:

$ ps -U $USER -LP | egrep 'chromi|PID' | head -4
  PID   LWP PSR TTY          TIME CMD
 6457  6457   3 ?        00:01:19 chromium-browse
 6457  6464   1 ?        00:00:00 chromium-browse
 6457  6465   2 ?        00:00:00 chromium-browse
杀手六號 2024-11-09 15:49:21

哪个是多个处理器?根据联机帮助页,它没有提供此选项。但在我的 Debian 稳定系统上,它接受未记录的 -o cpu


after looking at the source, and the output of ps L, I believe your answer is either the cpuid or sgi_p output options, column IDs CPUID and P, respectively.


And 'cpu' should work according to this note in output.c, but it's currently tied to the 'nop' output pr_nop():

{"cpu", "CPU", pr_nop, sr_nop, 3, 0, BSD, AN|RIGHT}, /* FIXME ... HP-UX 希望将此作为 SMP 的 CPU 编号? */

which of multiple processors? it does not offer an option for that according to the manpage. but on my Debian stable system it accepts the undocumented -o cpu


after looking at the source, and the output of ps L, I believe your answer is either the cpuid or sgi_p output options, column IDs CPUID and P, respectively.


And 'cpu' should work according to this note in output.c, but it's currently tied to the 'nop' output pr_nop():

{"cpu", "CPU", pr_nop, sr_nop, 3, 0, BSD, AN|RIGHT}, /* FIXME ... HP-UX wants this as the CPU number for SMP? */

寻找一个思念的角度 2024-11-09 15:49:21

同样被低估的是:

mpstat -I ALL 1 | less -SR

您可以添加迭代计数(例如仅一次迭代的 mpstat 1 1 )。

要仍然有彩色终端输出,请告诉 mpstat

S_COLORS=always mpstat -I ALL 1 | less -SR

在此处输入图像描述

要在终端上静态更新而不滚动:

watch -wcn .5 S_COLORS=always mpstat -I ALL 1 1 

在此处输入图像描述

Also much underrated:

mpstat -I ALL 1 | less -SR

You can add an iteration count (like mpstat 1 1 for just one iteration).

To still have color terminal output, tell mpstat:

S_COLORS=always mpstat -I ALL 1 | less -SR

enter image description here

To have it statically updating on a terminal without scrolling:

watch -wcn .5 S_COLORS=always mpstat -I ALL 1 1 

enter image description here

奈何桥上唱咆哮 2024-11-09 15:49:21

我在Arch上这样做了,它可能会帮助那里的人:

ps -C "process" -L -o pid,lwp,pcpu,cpuid,time
  • -C:选择名为“process”的进程
  • -L:列出进程线程
  • - o:指定输出信息
    • pid:进程ID
    • lwp:轻量级进程(线程)
    • pcpu:CPU 使用率(百分比)
    • cpuid:CPU ID
    • 时间:线程时间(从开始算起)

I did it this way on Arch, it might help someone out there:

ps -C "process" -L -o pid,lwp,pcpu,cpuid,time
  • -C: select the process named "process"
  • -L: list the process threads
  • -o: specify output info
    • pid: process id
    • lwp: light weight process (thread)
    • pcpu: CPU usage (percent)
    • cpuid: CPU id
    • time: thread time (from start)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文