[英]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
). 两个名称的原因是为了兼容Solaris (
psr
)和NetBSD / OpenBSD ( cpuid
)。
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
ps L
, I believe your answer is either the cpuid
or sgi_p
output options, column IDs CPUID and P, respectively.
ps L
的输出之后,我相信您的答案分别是cpuid
或sgi_p
输出选项,列ID CPUID和P.
{"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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.