简体   繁体   English

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

[英]ps utility in linux (procps), how to check which CPU is used

It is about procps package, utility ps for linux. 它是关于procps包,linux的实用程序ps

Can it print the number of last used CPU for each process (thread)? 它可以打印每个进程(线程)的最后使用的CPU数量吗?

Update: Not a CPU Time (10 seconds), but a CPU NUMBER (CPU0,CPU5,CPU123) 更新:不是CPU时间(10秒),而是CPU NUMBER(CPU0,CPU5,CPU123)

The ps(1) man page says you can use the psr field: ps(1)手册页说你可以使用psr字段:

  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. 或者您可以使用cpuid字段,它执行相同的操作。

$ 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 ). 两个名称的原因是为了兼容Solarispsr )和NetBSD / OpenBSDcpuid )。

To get threads too, add the -L option (and the lwp field if you are using -o ). 要获取线程,请添加-L选项(如果使用-o ,则添加lwp字段)。

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: 还有一个未记录的-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

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 但在我的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. 在查看源和ps L的输出之后,我相信您的答案分别是cpuidsgi_p输出选项,列ID CPUID和P.
And 'cpu' should work according to this note in output.c, but it's currently tied to the 'nop' output pr_nop(): 'cpu' 应该按照output.c中的这个注释工作,但是它当前与'nop'输出pr_nop()相关联:

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

也被低估了:

mpstat -I ALL 1 | less -SR

I did it this way on Arch, it might help someone out there: 我在Arch上这样做了,它可以帮助那里的人:

ps -C "process" -L -o pid,lwp,pcpu,cpuid,time
  • -C : select the process named "process" -C :选择名为“process”的进程
  • -L : list the process threads -L :列出进程线程
  • -o : specify output info -o :指定输出信息
    • pid : process id pid :进程ID
    • lwp : light weight process (thread) lwp :轻量级进程(线程)
    • pcpu : CPU usage (percent) pcpu :CPU使用率(百分比)
    • cpuid : CPU id cpuid :CPU ID
    • time : thread time (from start) 时间 :线程时间(从开始)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM